Inserting variable outputs into different ranges

G

Genix

Hello,

As simple as it may seem, I require some help.
I have used userforms to collect information from the user and stored them
in "public declared variables". So using the break point I see that the value
of each declared variable is retained.

I have a worksheet with eight ranges (each Range has ten rows and eight
columns); each column is to hold a separate piece of information. I want VBA
to transfer the info in those variables to the ranges for every session.


When I execute the sub it gets to a point and jumps right to the last Else
statement popping up the message box. I do not know why but it keeps skipping
the IF . . Then ... ElseIf construct.

I know its a clumsy route I took, does anyone have some valuable assistance
to provide? Thank you

Here is the relevant section of the code:

Worksheets("project Database").Activate

IF PId = "G" Then

(‘This determines the next empty row within the range)
NextRow1 = Application.WorksheetFunction.CountA(Range("A78:A88")) + 1

(‘This transfers the variable)
Cells(NextRow1, 1) = Variable1

NextRow2 = Application.WorksheetFunction.CountA(Range("B78:B88")) + 1
Cells(NextRow2, 2) = Variable2

NextRow3 = Application.WorksheetFunction.CountA(Range("C78:C88")) + 1
Cells(NextRow3, 3) = Variable3
 
J

JLGWhiz

Without knowing what Pld is, i.e. data type, it is difficult to say. But,
if Pld is a range address then:

If Range(Pld).Value = "G" Then

if Pld is a range object then:

If Pld.Value = "G" Then

Otherwise, if Pld is just a variant variable that holds a data value then it
must not be finding "G" or "H".

Try stepping through the macro using F8 and use the mouse over to see what
value the Pld variable holds at the first If statement. Or put a message
box right after that line and see if you get surprised by what you see.
 
G

Genix

To JLGWhiz:
Just to show appreciation and say mighty thanks. This community and forum
has been very helpful to me. My VBA project is now up & running.

PId was a variable and I was equating it to a variable that had not yet been
transferred. Its tricky VBA, you need understanding and common sense to
overcome 'your own' errors.

Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top