any help?

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

Guest

hello, i am trying to do as below, but it says compile error, end with
without with? which seems silly to me but i am obviously doing something wrong

**********************************************************************
Sub PrintCode()
Dim i As Integer, c As Integer, Q As Integer
c = 0

With Sheets("MacroData")

For Q = 2 To 46
B = Cells(Q, 2).Value
End With

With Sheets("Salary ect")

For i = 1 To 10000
A = Left(Cells(i, 1), 3).Value
End With

If A = B Then
With Sheets("macrodata")
Cells(i, 5).Value = 1

End With
Next

End Sub
**********************************************************************
i am using two sheets, i refers to
sheet 1 and Q refers to sheet 2. I want say first Q to = 2 and then the loop
for i to run all the way through to 10000 while Q = 2 and where whats in
cells(Q , 2) and cells(i , 1) match for a 1 to be put in cells(i , 5) on
sheet 2 (Q sheet) and once the loop has reached 10000 i want the next Q to be
activated so Q=3 of i loop 1 to 10000,

any help please

thanks,

andy
 
for the with statement to do anything, you need to put a period before the
"cells"

Sub PrintCode()
Dim i As Integer, c As Integer, Q As Integer
c = 0


For Q = 2 To 46
With Sheets("MacroData")
B = .Cells(Q, 2).Value
End With


For i = 1 To 10000
With Sheets("Salary ect")
A = Left(.Cells(i, 1), 3).Value
End With

If A = B Then
With Sheets("macrodata")
.Cells(i, 5).Value = 1
End With
End If
Next i
Next Q
End Sub
 
hey tom,

when i try using the code you have put it tells me that
With Sheets("Salary ect")
subscript out of range

do you know why?

thanks

Andy
 
Is that a typo from your original code, should it be

With Sheets("Salary etc")

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
The reason is you don't have a worksheet named Salary ect - Bob suggested
what it might be named.

I didn't change any sheet names in your code.
 

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