Check value on another sheet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Thanks for taking the time to read my question.

I have 2 sheets and am on the first one. The Second one "qcust" has my data
on it and I want to go through it row by row until there is no data left.

Why can't I do this? It gives me an application error

Do Until Worksheets("qcust").Cells(TheRow, TheCol) = ""

Here is the full code.

Sub MergeAndPrint()
Dim TheRow As Integer

TheRow = 2

Worksheets("qcust").Select

Do Until Worksheets("qcust").Cells(TheRow, TheCol) = ""
Range("D3") = Sheets("qcust").Cells(TheRow, 2).Value
Range("D4") = Sheets("qcust").Cells(TheRow, 3).Value
Range("D8") = Sheets("qcust").Cells(TheRow, 1).Value

TheRow = TheRow + 1
Loop

MsgBox "Complete"

End Sub

Thanks,

Brad
 
3 things,
1) TheCol is never set so it is checking Column 0 which is invalid
2) You don't want to select the "qcust" sheet
3) TheRow should be a long. There may not be 32,000 rows but it is a good
habit to make row index varialbles longs.

Peter Richardson
 
Brad,

The variable TheCol is not defined/initialized. Try:

Do Until Worksheets("qcust").Cells(TheRow, 1) = ""
 
It gives me an application error

Always good to be very specific (the text of the error message, not just its
number)

Have you set a value for TheCol? If not it's 0 which is not a valid column
number.

--
Jim
| Thanks for taking the time to read my question.
|
| I have 2 sheets and am on the first one. The Second one "qcust" has my
data
| on it and I want to go through it row by row until there is no data left.
|
| Why can't I do this? It gives me an application error
|
| Do Until Worksheets("qcust").Cells(TheRow, TheCol) = ""
|
| Here is the full code.
|
| Sub MergeAndPrint()
| Dim TheRow As Integer
|
| TheRow = 2
|
| Worksheets("qcust").Select
|
| Do Until Worksheets("qcust").Cells(TheRow, TheCol) = ""
| Range("D3") = Sheets("qcust").Cells(TheRow, 2).Value
| Range("D4") = Sheets("qcust").Cells(TheRow, 3).Value
| Range("D8") = Sheets("qcust").Cells(TheRow, 1).Value
|
| TheRow = TheRow + 1
| Loop
|
| MsgBox "Complete"
|
| End Sub
|
| Thanks,
|
| Brad
 
Thanks Vergel,

Sometimes another set of eyes helps. I thought I got rid of all of those.

Thanks again,

Brad
 

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

Back
Top