Hi all,
I have a workbook with multiple sheets in it, what I am trying to accomplish is when I push a cmdbtn with a given users name as its caption the code will scan through all the worksheets select the range where = to the sheet1.cmdbtn.caption then paste a copy into a ‘results’ sheet.
The code itself was written to scan through one sheet than I was going to reproduce it to scan through the remaining sheets not ideal I know, however I’m still getting to grips with excel vba.
The code:
Application.Calculation = xlCalculationManual
frmworking.Show (0)
DoEvents
scandown = 1
foundagent = 0
Do
scandown = scandown + 1
holdagent = Sheet1.btnag6.Caption
HoldSelectedagent = Sheet1.btnag6.Caption
If holdagent = HoldSelectedagent Then
foundagent = 1
leftcell = "A" & scandown
rightcell = "H" & scandown
checkblank = 1
Do
checkblank = checkblank + 1
Loop Until Sheet12.Cells(checkblank, 1) = ""
pastetocells = "A" & checkblank
Sheet12.Range(pastetocells & ":H" & checkblank).Value = Sheet4.Range(leftcell, rightcell).Value
End If
Loop Until foundagent = 1 And holdagent <> HoldSelectedagent
frmworking.Hide
Application.Calculation = xlCalculationAutomatic
Oh I should also mention that the above falls over at holdagent=””
Any suggestions appreciated Guys.
Thanks in advance.
I have a workbook with multiple sheets in it, what I am trying to accomplish is when I push a cmdbtn with a given users name as its caption the code will scan through all the worksheets select the range where = to the sheet1.cmdbtn.caption then paste a copy into a ‘results’ sheet.
The code itself was written to scan through one sheet than I was going to reproduce it to scan through the remaining sheets not ideal I know, however I’m still getting to grips with excel vba.
The code:
Application.Calculation = xlCalculationManual
frmworking.Show (0)
DoEvents
scandown = 1
foundagent = 0
Do
scandown = scandown + 1
holdagent = Sheet1.btnag6.Caption
HoldSelectedagent = Sheet1.btnag6.Caption
If holdagent = HoldSelectedagent Then
foundagent = 1
leftcell = "A" & scandown
rightcell = "H" & scandown
checkblank = 1
Do
checkblank = checkblank + 1
Loop Until Sheet12.Cells(checkblank, 1) = ""
pastetocells = "A" & checkblank
Sheet12.Range(pastetocells & ":H" & checkblank).Value = Sheet4.Range(leftcell, rightcell).Value
End If
Loop Until foundagent = 1 And holdagent <> HoldSelectedagent
frmworking.Hide
Application.Calculation = xlCalculationAutomatic
Oh I should also mention that the above falls over at holdagent=””
Any suggestions appreciated Guys.
Thanks in advance.