Data not pulling from secondary workbook

DanSMT

Board Regular
Joined
Sep 13, 2019
Messages
203
Office Version
  1. 2013
Platform
  1. Windows
Hey all,

Im trying to pull data from a secondary workbook based on the information entered into an array of textboxes on a userform. Everything else appears to be working except when trying to pull the information over from the secondary workbook. Any ideas?

VBA Code:
Private Sub testcb_Click()

Dim i2 As Long
For i2 = 1 To 20
If Me.Controls("RITB" & i2).Text = vbNullString Then
Else
Worksheets("fai").Copy after:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = Me.Controls("RITB" & i2).Text & " FAI"
ActiveSheet.Range("c4").Value = Me.Controls("RITB" & i2).Text
Dim source, target As Worksheet
Set target = Workbooks("New RI Form rev9 - Develop Mode - DO NOT USE.xlsb").Sheets("RI Log")

targetlastrow = target.Range("B" & target.Rows.Count).End(xlUp).Row

    For j = 2 To targetlastrow
        If target.Range("B" & j).Value = ActiveSheet.Range("c4").Value Then

        ActiveSheet.Range("A9").Value = "A"
        ActiveSheet.Range("B9").Value = target.Cells(rng.Row, 90).Value
        ActiveSheet.Range("C9").Value = target.Cells(rng.Row, 91).Value
        ActiveSheet.Range("D9").Value = target.Cells(rng.Row, 89).Value

        End If
    Next j

End If
Next

End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Think I screwed something up.


VBA Code:
Private Sub testcb_Click()

Dim i2 As Long
For i2 = 1 To 20
If Me.Controls("RITB" & i2).Text = vbNullString Then
Else
Worksheets("fai").Copy after:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = Me.Controls("RITB" & i2).Text & " FAI"
ActiveSheet.Range("c4").Value = Me.Controls("RITB" & i2).Text

Dim target As Workbook
Set target = Workbooks("New RI Form rev9 - Develop Mode - DO NOT USE.xlsb")

Dim targetsheet As Worksheet
Set targetsheet = Sheets("RI Log")

targetlastrow = target.targetsheet.Range("B" & targetsheet.Rows.Count).End(xlUp).Row

    For j = 2 To targetlastrow
        If targetsheet.Range("B" & j).Value = ActiveSheet.Range("c4").Value Then

        ActiveSheet.Range("A9").Value = "A"
        ActiveSheet.Range("B9").Value = targetsheet.Cells(rng.Row, 90).Value
        ActiveSheet.Range("C9").Value = targetsheet.Cells(rng.Row, 91).Value
        ActiveSheet.Range("D9").Value = targetsheet.Cells(rng.Row, 89).Value

        End If
    Next j

End If
Next

End Sub
 
Upvote 0
All of the places that you have targetsheet, you will need it to be target.targetsheet

From the targetlastrow = line on down.
 
Upvote 0
All of the places that you have targetsheet, you will need it to be target.targetsheet

From the targetlastrow = line on down.
Fixed all of that.

Set targetsheet = Sheets("RI Log")

Error Subscript out of range again.
 
Upvote 0
VBA Code:
Private Sub testcb_Click()

Dim i2 As Long
For i2 = 1 To 20
If Me.Controls("RITB" & i2).Text = vbNullString Then
Else
Worksheets("fai").Copy after:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = Me.Controls("RITB" & i2).Text & " FAI"
ActiveSheet.Range("c4").Value = Me.Controls("RITB" & i2).Text

Dim target As Workbook
Set target = Workbooks("New RI Form rev9 - Develop Mode - DO NOT USE.xlsb")

Dim targetsheet As Worksheet
Set targetsheet = Sheets("RI Log")

targetlastrow = target.targetsheet.Range("B" & target.targetsheet.Rows.Count).End(xlUp).Row

    For j = 2 To targetlastrow
        If target.targetsheet.Range("B" & j).Value = ActiveSheet.Range("c4").Value Then

        ActiveSheet.Range("A9").Value = "A"
        ActiveSheet.Range("B9").Value = target.targetsheet.Cells(rng.Row, 90).Value
        ActiveSheet.Range("C9").Value = target.targetsheet.Cells(rng.Row, 91).Value
        ActiveSheet.Range("D9").Value = target.targetsheet.Cells(rng.Row, 89).Value

        End If
    Next j

End If
Next

End Sub
 
Upvote 0
Are you positive there is a sheet called RI Log in the target workbook?
 
Upvote 0
if so: Try changing:
VBA Code:
Set targetsheet = Sheets("RI Log")

to:
VBA Code:
Set targetsheet = target.Sheets("RI Log")
 
Upvote 0
new error now.. :(

targetlastrow = target.targetsheet.Range("B" & target.targetsheet.Rows.Count).End(xlUp).Row

Object doesn't support this property or method
 
Upvote 0
Since you made the last change, remove the target. from there down. so you just want to use targetsheet instead of target.targetsheet
 
Upvote 0

Forum statistics

Threads
1,215,504
Messages
6,125,185
Members
449,213
Latest member
Kirbito

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top