VBAExpertNot
New Member
- Joined
- Jul 2, 2017
- Messages
- 2
Hello,
Conceptually, I'm thinking I should be able to do this, but I'm stuck one line of code.
Background: File has 2 sheets. Each sheet, in its column A, has different categories which are string dimensions/values. But each sheet often has the same string value, such as "Ajax", in my code example.
I thought I could do a separate Find for each sheet, and then store each value for later use.
However, when I want to copy a row of data (about 31 columns of numbers) from one sheet to the other that does not have the data, my code gets stuck. It gets stuck on that one line of code.
This is my first use of Find, so I could be easily missing a nuance in the code.
Any feedback or help would be much appreciated.
code
Sub FindStr()
Dim rFndCell As Range
Dim rFndCell2 As Range
Dim strData As String
Dim stFnd As String
Dim fRow As Integer
Dim sh As Worksheet
Dim ws As Worksheet
Set ws = Sheets("OriginalStats")
Set sh = Sheets("TargetTab")
stFnd = "Ajax"
With sh
Set rFndCell = .Range("A:A").Find(stFnd, LookIn:=xlValues)
If Not rFndCell Is Nothing Then
fRow = rFndCell.Row
Else 'Can't find the item
MsgBox "No Find"
End If
End With
With ws
Set rFndCell2 = .Range("A:A").Find(stFnd, LookIn:=xlValues)
If Not rFndCell2 Is Nothing Then
fRow2 = rFndCell2.Row
ws.Range(fRow2, 1).Offset(0, 5).Resize(0, 31).Copy Destination:=sh(fRow, 5).Offset(1, 0)
Else 'Can't find the item
MsgBox "No Find"
End If
End With
End Sub
/code
Conceptually, I'm thinking I should be able to do this, but I'm stuck one line of code.
Background: File has 2 sheets. Each sheet, in its column A, has different categories which are string dimensions/values. But each sheet often has the same string value, such as "Ajax", in my code example.
I thought I could do a separate Find for each sheet, and then store each value for later use.
However, when I want to copy a row of data (about 31 columns of numbers) from one sheet to the other that does not have the data, my code gets stuck. It gets stuck on that one line of code.
This is my first use of Find, so I could be easily missing a nuance in the code.
Any feedback or help would be much appreciated.
code
Sub FindStr()
Dim rFndCell As Range
Dim rFndCell2 As Range
Dim strData As String
Dim stFnd As String
Dim fRow As Integer
Dim sh As Worksheet
Dim ws As Worksheet
Set ws = Sheets("OriginalStats")
Set sh = Sheets("TargetTab")
stFnd = "Ajax"
With sh
Set rFndCell = .Range("A:A").Find(stFnd, LookIn:=xlValues)
If Not rFndCell Is Nothing Then
fRow = rFndCell.Row
Else 'Can't find the item
MsgBox "No Find"
End If
End With
With ws
Set rFndCell2 = .Range("A:A").Find(stFnd, LookIn:=xlValues)
If Not rFndCell2 Is Nothing Then
fRow2 = rFndCell2.Row
ws.Range(fRow2, 1).Offset(0, 5).Resize(0, 31).Copy Destination:=sh(fRow, 5).Offset(1, 0)
Else 'Can't find the item
MsgBox "No Find"
End If
End With
End Sub
/code