New Posts  All Forums:Forum Nav:

VBA Assistance...

post #1 of 8
Thread Starter 
So I have a small problem, and I'm horrible at explaining things but I'm going to give it a shot... redface.gif

Basically, I'm writing a macro for work, and the last step I'm stuck on is validating a variable in Excel. I have a pop up box that asks for someone to input a last name in all caps, and everything works great as long as the name they type is actually in the file and they spelled it correctly with all caps. If one of those criteria fail, the macro dies and you have to restart from scratch. I am looking for help with two possible solutions.

Solution #1.

Create a drop down box for the person to select the name from. The list in the drop down box would need to reference multiple columns in an excel tab. I haven't really found any solutions to creating a drop-down box in a pop-up window in Excel when I searched the web, so I don't even know if this is viable.

Solution #2.

Take the input from the box, and check the tab in Excel to verify the name is in the sheet. If the name is not in the sheet, have an error message pop up informing the user the name is incorrect, and allow them to try to input the name again.

Again, I'm pretty bad at explaining things, I hope the explanation is sufficient. If not, ask any questions, and thanks in advance for any support cheers.gif
First Time Build
(20 items)
 
  
CPUMotherboardGraphicsGraphics
Intel Core i7 920 MSI X58 Pro-E (MS-7522) EVGA GeForce GTX 460 EVGA GeForce GTX 460 
GraphicsRAMRAMRAM
Galaxy GeForce GTX 460 Corsair  Corsair  Corsair  
Hard DriveOptical DriveCoolingOS
Seagate Barracuda 7200.12 Sony DVD+-RW Noctua NH-D14 Windows 7 64bit 
MonitorMonitorKeyboardPower
Acer P215H Acer P221W Dynex Silverstone OP1000-E 1kW PSU 
CaseMouseMouse PadAudio
Cooler Master HAF 932 Dynex Dynex ASUS Xonar DG 
  hide details  
Reply
First Time Build
(20 items)
 
  
CPUMotherboardGraphicsGraphics
Intel Core i7 920 MSI X58 Pro-E (MS-7522) EVGA GeForce GTX 460 EVGA GeForce GTX 460 
GraphicsRAMRAMRAM
Galaxy GeForce GTX 460 Corsair  Corsair  Corsair  
Hard DriveOptical DriveCoolingOS
Seagate Barracuda 7200.12 Sony DVD+-RW Noctua NH-D14 Windows 7 64bit 
MonitorMonitorKeyboardPower
Acer P215H Acer P221W Dynex Silverstone OP1000-E 1kW PSU 
CaseMouseMouse PadAudio
Cooler Master HAF 932 Dynex Dynex ASUS Xonar DG 
  hide details  
Reply
post #2 of 8
Thread Starter 
Going to bump this, I found a workaround to it that gets the job done. So I suppose this question doesn't need to be answered, but it looks like (from searching around on google) that there might be ways to create drop down lists to select from. However, I've tried putting the code into my macro and it errors out on me. In the end, I am sure I'll eventually figure out a way to make it work, but I wanted to post here to see if anyone had any experience creating this and had a shortcut or tip cheers.gif
First Time Build
(20 items)
 
  
CPUMotherboardGraphicsGraphics
Intel Core i7 920 MSI X58 Pro-E (MS-7522) EVGA GeForce GTX 460 EVGA GeForce GTX 460 
GraphicsRAMRAMRAM
Galaxy GeForce GTX 460 Corsair  Corsair  Corsair  
Hard DriveOptical DriveCoolingOS
Seagate Barracuda 7200.12 Sony DVD+-RW Noctua NH-D14 Windows 7 64bit 
MonitorMonitorKeyboardPower
Acer P215H Acer P221W Dynex Silverstone OP1000-E 1kW PSU 
CaseMouseMouse PadAudio
Cooler Master HAF 932 Dynex Dynex ASUS Xonar DG 
  hide details  
Reply
First Time Build
(20 items)
 
  
CPUMotherboardGraphicsGraphics
Intel Core i7 920 MSI X58 Pro-E (MS-7522) EVGA GeForce GTX 460 EVGA GeForce GTX 460 
GraphicsRAMRAMRAM
Galaxy GeForce GTX 460 Corsair  Corsair  Corsair  
Hard DriveOptical DriveCoolingOS
Seagate Barracuda 7200.12 Sony DVD+-RW Noctua NH-D14 Windows 7 64bit 
MonitorMonitorKeyboardPower
Acer P215H Acer P221W Dynex Silverstone OP1000-E 1kW PSU 
CaseMouseMouse PadAudio
Cooler Master HAF 932 Dynex Dynex ASUS Xonar DG 
  hide details  
Reply
post #3 of 8
Thread Starter 
Code:
Dim source As String
    source = InputBox("Choose source data by entering source type:          B2 or F1", "Source Data")
    Do
    Do While (source <> "F1" Or source <> "B2")
    invalidentry = MsgBox("Invalid Entry", vbOKOnly + vbInformation)
    source = InputBox("Choose source data by entering source type:          B2 or F1", "Source Data")
        Exit Do
    Loop
Loop Until source = "F1" Or source = "B2"
If (source <> "") Then
.
.
.
End If

Alright guys, bumping again, sorry frown.gif I'm really not a programmer, but I'm trying to hack 'n slash my way through this. Been on the back burner the last week (priorities) but I put some time into it over the long weekend, and after doing a bit of googling and thinking this is the code I've come up with. So, it almost works, but the initial entry is always shown as an invalid entry. I know there's something wrong with the loop, but it seems like I'm setting it up correctly. Any insight? cheers.gif

::edit:: btw, I realize this question is a bit different from my original question. But once I figure out what I'm doing wrong with my entry and exit on the "for loop" then my original question will be answered. But this code is more concise and I put it here because it's less confusing. Still can't figure out how to create a pop up with a drop down menu in VBA, but I've given up on that as that's just nice looking and I found a functioning way to accomplish my original task smile.gif

::edit#2::
Warning: Spoiler! (Click to show)
Code:
Dim source As String
    Dim source2 As Integer
    
    source2 = 1
    
    Do
    Do While (source2 = 1)
    source = InputBox("Choose source data by entering source type:  B2 or F1", "Source Data")
    If (source = "F1") Then
    source2 = 0
    MsgBox "Entry Found"
    End If
    If (source = "B2") Then
    source2 = 0
    MsgBox "Entry Found"
    End If
    If (source2 <> 0) Then
    source2 = 1
    MsgBox "Invalid Entry"
    End If
    Exit Do
    Loop
    Loop Until source2 = 0

Alright, so it looks like I figured out an ugly way to make it work. Since this is a pretty low level macro, I'm guessing it isn't worth my time to make it efficient because it wouldn't shave any noticeable time off? So far this seems to accomplish exactly what I want it to do, which is a good thing. But still, if anyone has any tips on how to improve the code, or make it more readable, I would really appreciate it. With just starting to learn how to code, I'm still very new and not very good at it, so any and all criticisms are quite welcomed cheers.gif

::edit #3::

Yay for more edits!!! rolleyes.gif So I just realized, I have an infinite loop in my code frown.gif If someone selects "cancel" on the box asking for source type, then source2 will forever remain 1, and the macro will keep looping until a correct value is entered. I've tried inserting a line of code in there saying
Code:
If (source <> "") Then...End If
but then VBA pops up telling me that I have an error, "Do without loop" or something like that. So, basically, this code works, as long as the person doesn't change their mind and want to cancel. I have no idea how to put another "If" statement within the "do" loop, unless...

Be back in a bit, light bulb just went off biggrin.gif nvm, the lightbulb had a flash then burnt out. Need a new lightbulb, OCN coding vets cheers.gif
Edited by b3machi7ke - 5/29/12 at 12:29pm
First Time Build
(20 items)
 
  
CPUMotherboardGraphicsGraphics
Intel Core i7 920 MSI X58 Pro-E (MS-7522) EVGA GeForce GTX 460 EVGA GeForce GTX 460 
GraphicsRAMRAMRAM
Galaxy GeForce GTX 460 Corsair  Corsair  Corsair  
Hard DriveOptical DriveCoolingOS
Seagate Barracuda 7200.12 Sony DVD+-RW Noctua NH-D14 Windows 7 64bit 
MonitorMonitorKeyboardPower
Acer P215H Acer P221W Dynex Silverstone OP1000-E 1kW PSU 
CaseMouseMouse PadAudio
Cooler Master HAF 932 Dynex Dynex ASUS Xonar DG 
  hide details  
Reply
First Time Build
(20 items)
 
  
CPUMotherboardGraphicsGraphics
Intel Core i7 920 MSI X58 Pro-E (MS-7522) EVGA GeForce GTX 460 EVGA GeForce GTX 460 
GraphicsRAMRAMRAM
Galaxy GeForce GTX 460 Corsair  Corsair  Corsair  
Hard DriveOptical DriveCoolingOS
Seagate Barracuda 7200.12 Sony DVD+-RW Noctua NH-D14 Windows 7 64bit 
MonitorMonitorKeyboardPower
Acer P215H Acer P221W Dynex Silverstone OP1000-E 1kW PSU 
CaseMouseMouse PadAudio
Cooler Master HAF 932 Dynex Dynex ASUS Xonar DG 
  hide details  
Reply
post #4 of 8
Thread Starter 
sheesh...tough club to get any attention...alright alright, what kind of freebie/giveaway do I have to do? cheers.gif
Edited by b3machi7ke - 6/4/12 at 9:42am
First Time Build
(20 items)
 
  
CPUMotherboardGraphicsGraphics
Intel Core i7 920 MSI X58 Pro-E (MS-7522) EVGA GeForce GTX 460 EVGA GeForce GTX 460 
GraphicsRAMRAMRAM
Galaxy GeForce GTX 460 Corsair  Corsair  Corsair  
Hard DriveOptical DriveCoolingOS
Seagate Barracuda 7200.12 Sony DVD+-RW Noctua NH-D14 Windows 7 64bit 
MonitorMonitorKeyboardPower
Acer P215H Acer P221W Dynex Silverstone OP1000-E 1kW PSU 
CaseMouseMouse PadAudio
Cooler Master HAF 932 Dynex Dynex ASUS Xonar DG 
  hide details  
Reply
First Time Build
(20 items)
 
  
CPUMotherboardGraphicsGraphics
Intel Core i7 920 MSI X58 Pro-E (MS-7522) EVGA GeForce GTX 460 EVGA GeForce GTX 460 
GraphicsRAMRAMRAM
Galaxy GeForce GTX 460 Corsair  Corsair  Corsair  
Hard DriveOptical DriveCoolingOS
Seagate Barracuda 7200.12 Sony DVD+-RW Noctua NH-D14 Windows 7 64bit 
MonitorMonitorKeyboardPower
Acer P215H Acer P221W Dynex Silverstone OP1000-E 1kW PSU 
CaseMouseMouse PadAudio
Cooler Master HAF 932 Dynex Dynex ASUS Xonar DG 
  hide details  
Reply
post #5 of 8
Quote:
Originally Posted by b3machi7ke View Post

sheesh...tough club to get any attention...alright alright, what kind of freebie/giveaway do I have to do? cheers.gif

Not too many people frequent this dark and hidden corner of overclock.net wink.gif
 
My first rig!
(16 items)
 
 
CPUMotherboardGraphicsGraphics
Intel Core i5 2500K SABERTOOTH P67 NVIDIA GeForce GTX 480 NVIDIA GeForce GTX 480 
RAMRAMHard DriveHard Drive
Corsair  Corsair  500GB HDD 7200rpm M4 Crucial 
Optical DriveCoolingOSMonitor
None Hyper 212 plus Win7 x64 Viewsonic "23 or "24 1080p 
Case
CoolerMaster HAF 912 
CPUMotherboardGraphicsRAM
FX 4100 MSI 970A-G45 EVGA GTX 460 8 GB Corsair Vengeance 1600 MHz 
Hard DriveOptical DriveCoolingCooling
500GB Hard Drive USB DVD/CD Corsair H50 Graphics card aftermarket cooler 
OSMonitorKeyboardPower
Win 7 x64 ViewSonic 24" Logitech 500W CoolerMaster 
CaseMouseAudioOther
NVIDIA Elite 334 LG Old speakers USB Lamp 
  hide details  
Reply
 
My first rig!
(16 items)
 
 
CPUMotherboardGraphicsGraphics
Intel Core i5 2500K SABERTOOTH P67 NVIDIA GeForce GTX 480 NVIDIA GeForce GTX 480 
RAMRAMHard DriveHard Drive
Corsair  Corsair  500GB HDD 7200rpm M4 Crucial 
Optical DriveCoolingOSMonitor
None Hyper 212 plus Win7 x64 Viewsonic "23 or "24 1080p 
Case
CoolerMaster HAF 912 
CPUMotherboardGraphicsRAM
FX 4100 MSI 970A-G45 EVGA GTX 460 8 GB Corsair Vengeance 1600 MHz 
Hard DriveOptical DriveCoolingCooling
500GB Hard Drive USB DVD/CD Corsair H50 Graphics card aftermarket cooler 
OSMonitorKeyboardPower
Win 7 x64 ViewSonic 24" Logitech 500W CoolerMaster 
CaseMouseAudioOther
NVIDIA Elite 334 LG Old speakers USB Lamp 
  hide details  
Reply
post #6 of 8
Thread Starter 
So it's been a week since I last worked on this, thankfully the boss-lady understands I'm not a coder, so she had me working on this way before we need it smile.gif Been up and running successfully now, but this morning as I was sipping my coffee I had a revelation smil3dbd4e4c2e742.gif All I needed to make this work was a simple
Code:
If (source = "") Then
    source2 = 0
    End If
If (source <> "") Then
...
End If

I suppose with a bit of experience I should have known that. I was going to try to mess with the vbYesNoCancel box, that way I would be "correctly" handling the cancel option, but to be honest I've spent way more time on this than I wanted to. I think it's safe to say I will not be entering the ranks of programmers anytime soon!
First Time Build
(20 items)
 
  
CPUMotherboardGraphicsGraphics
Intel Core i7 920 MSI X58 Pro-E (MS-7522) EVGA GeForce GTX 460 EVGA GeForce GTX 460 
GraphicsRAMRAMRAM
Galaxy GeForce GTX 460 Corsair  Corsair  Corsair  
Hard DriveOptical DriveCoolingOS
Seagate Barracuda 7200.12 Sony DVD+-RW Noctua NH-D14 Windows 7 64bit 
MonitorMonitorKeyboardPower
Acer P215H Acer P221W Dynex Silverstone OP1000-E 1kW PSU 
CaseMouseMouse PadAudio
Cooler Master HAF 932 Dynex Dynex ASUS Xonar DG 
  hide details  
Reply
First Time Build
(20 items)
 
  
CPUMotherboardGraphicsGraphics
Intel Core i7 920 MSI X58 Pro-E (MS-7522) EVGA GeForce GTX 460 EVGA GeForce GTX 460 
GraphicsRAMRAMRAM
Galaxy GeForce GTX 460 Corsair  Corsair  Corsair  
Hard DriveOptical DriveCoolingOS
Seagate Barracuda 7200.12 Sony DVD+-RW Noctua NH-D14 Windows 7 64bit 
MonitorMonitorKeyboardPower
Acer P215H Acer P221W Dynex Silverstone OP1000-E 1kW PSU 
CaseMouseMouse PadAudio
Cooler Master HAF 932 Dynex Dynex ASUS Xonar DG 
  hide details  
Reply
post #7 of 8
Quote:
Originally Posted by b3machi7ke View Post

I suppose with a bit of experience I should have known that. I was going to try to mess with the vbYesNoCancel box, that way I would be "correctly" handling the cancel option, but to be honest I've spent way more time on this than I wanted to. I think it's safe to say I will not be entering the ranks of programmers anytime soon!

Hahaha well you got it done. And yea, you ain't the only one feeling that way tongue.gif
 
My first rig!
(16 items)
 
 
CPUMotherboardGraphicsGraphics
Intel Core i5 2500K SABERTOOTH P67 NVIDIA GeForce GTX 480 NVIDIA GeForce GTX 480 
RAMRAMHard DriveHard Drive
Corsair  Corsair  500GB HDD 7200rpm M4 Crucial 
Optical DriveCoolingOSMonitor
None Hyper 212 plus Win7 x64 Viewsonic "23 or "24 1080p 
Case
CoolerMaster HAF 912 
CPUMotherboardGraphicsRAM
FX 4100 MSI 970A-G45 EVGA GTX 460 8 GB Corsair Vengeance 1600 MHz 
Hard DriveOptical DriveCoolingCooling
500GB Hard Drive USB DVD/CD Corsair H50 Graphics card aftermarket cooler 
OSMonitorKeyboardPower
Win 7 x64 ViewSonic 24" Logitech 500W CoolerMaster 
CaseMouseAudioOther
NVIDIA Elite 334 LG Old speakers USB Lamp 
  hide details  
Reply
 
My first rig!
(16 items)
 
 
CPUMotherboardGraphicsGraphics
Intel Core i5 2500K SABERTOOTH P67 NVIDIA GeForce GTX 480 NVIDIA GeForce GTX 480 
RAMRAMHard DriveHard Drive
Corsair  Corsair  500GB HDD 7200rpm M4 Crucial 
Optical DriveCoolingOSMonitor
None Hyper 212 plus Win7 x64 Viewsonic "23 or "24 1080p 
Case
CoolerMaster HAF 912 
CPUMotherboardGraphicsRAM
FX 4100 MSI 970A-G45 EVGA GTX 460 8 GB Corsair Vengeance 1600 MHz 
Hard DriveOptical DriveCoolingCooling
500GB Hard Drive USB DVD/CD Corsair H50 Graphics card aftermarket cooler 
OSMonitorKeyboardPower
Win 7 x64 ViewSonic 24" Logitech 500W CoolerMaster 
CaseMouseAudioOther
NVIDIA Elite 334 LG Old speakers USB Lamp 
  hide details  
Reply
post #8 of 8
Thread Starter 
Quote:
Originally Posted by stryk3r1215 View Post

Hahaha well you got it done. And yea, you ain't the only one feeling that way tongue.gif

what??? You think I'm not a good coder??? sad-smiley-002.gif

But seriously, I know I'm not. Do you have opinions and/or suggestions on how to clean up what I've written here? I mean, I think it's pretty straightforward, and should anyone ever need to debug or modify the code it's very complex or confusing. But I know there's almost always room for improvements to code, which was one of the reasons I was here, to glean any insightful tips/hints/suggestions cheers.gif
First Time Build
(20 items)
 
  
CPUMotherboardGraphicsGraphics
Intel Core i7 920 MSI X58 Pro-E (MS-7522) EVGA GeForce GTX 460 EVGA GeForce GTX 460 
GraphicsRAMRAMRAM
Galaxy GeForce GTX 460 Corsair  Corsair  Corsair  
Hard DriveOptical DriveCoolingOS
Seagate Barracuda 7200.12 Sony DVD+-RW Noctua NH-D14 Windows 7 64bit 
MonitorMonitorKeyboardPower
Acer P215H Acer P221W Dynex Silverstone OP1000-E 1kW PSU 
CaseMouseMouse PadAudio
Cooler Master HAF 932 Dynex Dynex ASUS Xonar DG 
  hide details  
Reply
First Time Build
(20 items)
 
  
CPUMotherboardGraphicsGraphics
Intel Core i7 920 MSI X58 Pro-E (MS-7522) EVGA GeForce GTX 460 EVGA GeForce GTX 460 
GraphicsRAMRAMRAM
Galaxy GeForce GTX 460 Corsair  Corsair  Corsair  
Hard DriveOptical DriveCoolingOS
Seagate Barracuda 7200.12 Sony DVD+-RW Noctua NH-D14 Windows 7 64bit 
MonitorMonitorKeyboardPower
Acer P215H Acer P221W Dynex Silverstone OP1000-E 1kW PSU 
CaseMouseMouse PadAudio
Cooler Master HAF 932 Dynex Dynex ASUS Xonar DG 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming