Andrew - this loops thru col A looking for a certain text string. It then selects the same rows in colB:
Sub selectdiscontrg()
x = 0
For i = 1 To Range("A65536".End(xlUp).Row
If Range("A" & i).Text = "insert text here" Then
If x < 1 Then
rgSel = "B" & i 'change B to whatever column you want to select
Else
rgSel = rgSel & ",B" & i 'change B to whatever column you want to select
End If
x = x + 1
Else
End If
Next i
Range(rgSel).Select
End Sub
This does work, but the cells i want to selectd are always together, ie s1:s40 and this code selects on a individual basis. So the problem occurs because i was going to make this part of a paste command.
Sub SelectEmAll()
With ActiveSheet.Columns("S"
Set c = .Find("Text To Search For", Range("S1", LookIn:=xlValues, lookat:=xlWhole)
If Not c Is Nothing Then
fRow = c.Row
Else
MsgBox "No Matching Data Found"
Exit Sub
End If
End With
ctr = WorksheetFunction.CountIf(ActiveSheet.Range("S2:S" & Range("A65536".End(xlUp).Row), "Text To Search For"
Range("T" & fRow & ":T" & fRow + ctr - 1).Copy Destination:=Sheets("Sheet2".Range("A1"' change to whatever column you want to copy and whatever you want the destination to be - this is far quicker than select/copy/select/paste
End Sub
What i've tried to do is Select ie copy subcontractor using the commands on that workbook i sent you yesterday and then insert those rates into another workbook
I've been using this command which again is in the workbook i sent you yesterday:
Private Sub Image13_Click()
msheet = ActiveSheet.Name
Select Case msheet
Case "BoQ"
If Application.CutCopyMode = False Then
MsgBox "Please Select Subcontractor Rates To Paste!"
Else
Range("s:s".Select
Set Rng = Selection.Find(What:=ComboBox1.Text, After:=ActiveCell, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False)
If Rng Is Nothing Then
MsgBox "This Subcontractor Doesn't Exist!"
Exit Sub
End If
Rng.Activate
ActiveCell.Offset(0, -11).Select
Selection.PasteSpecial Paste:=xlPasteValues
End If
Case Else
MsgBox "Please Select Bill Of Quantities To Enter Rates"
End Select
End Sub
The trouble is that there might be an occasion when the areas are a diiferent size, and i don't want it to allow the paste to complete should this be the case.
The code above only pastes to one cell. The data copied might be several cells long, and it therefore ends up pasting to the same amount of cells. The amount of cells pasted should, & in most cases does match the number of selected reference in column S. It just on the odd occasion that they don't match that i would like it no to paste and warn me instead!
Not sure I understand how the code is working then -you have no loop to find more than 1 cell and I can't see a copy statement before the paste.....??? Rgds
~Geoff~
The copy statement is in a different code, we like to keep them seperate - some people in the office feel safer doing it this way.
I'll resend the workbook if that's OK. The copy command is on the 'Select Subs' tab, and the paste code is on the 'Enter Subs To BoQ' tab(this second tab is for uses with another workbook though, but i've included the 'BoQ' worksheet in this workbook to show you how it works.
Some users sometimes have alter the references on the 'BoQ' sheet 'Sub Ref' column and forget to alter the corresponding worksheets in this Sub Comp workbook. This is when the problems occur with the copy and paste.
So i need some code to warn me if the sizes are different!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.