extracting info

Countryboy69

Board Regular
Joined
Dec 7, 2018
Messages
77
is there a macro that once an external file is open it pulls certain info from it and plugs it in to various sheets?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hello Countryboy69

I hope this is what you are looking for.

Code:
Option Base 1
Sub TransferData()
    Dim ws1 As Worksheet: Set ws1 = ThisWorkbook.Sheets("Notes")
    Dim ws5 As Worksheet: Set ws5 = ThisWorkbook.Sheets("Sheet5")
    Dim NotesArray As Variant
    Dim Sheet5Array As Variant
    Dim NotesRng As Variant
    Dim NotesArrayR As Long
    Dim LoopNotesArrayR As Long
    Dim Sheet5ArrayR As Long
With ws1
    NotesArrayR = .Cells(Rows.Count, "A").End(xlUp).Row - 2
    Set NotesRng = .Range("F3", .Range("F3").End(xlDown).End(xlToLeft))
    NotesArray = NotesRng
End With
     ReDim Sheet5Array(NotesArrayR, 2)
     Sheet5ArrayR = 1
     
For LoopNotesArrayR = 1 To NotesArrayR
   If NotesArray(LoopNotesArrayR, 6) > 0 Then
      Sheet5Array(Sheet5ArrayR, 1) = NotesArray(LoopNotesArrayR, 1)
      Sheet5Array(Sheet5ArrayR, 2) = NotesArray(LoopNotesArrayR, 6)
      Sheet5ArrayR = Sheet5ArrayR + 1
   End If
Next

With ws5
    ws5.Activate
    Range("B3").Resize(UBound(Sheet5Array, 1), UBound(Sheet5Array, 2)) = Sheet5Array
End With
End Sub

Sorry it took so long but this has been a learning experience for me.

TotallyConfused
 
Upvote 0
Hello Countryboy69

I hope this is what you are looking for.

Code:
Option Base 1
Sub TransferData()
    Dim ws1 As Worksheet: Set ws1 = ThisWorkbook.Sheets("Notes")
    Dim ws5 As Worksheet: Set ws5 = ThisWorkbook.Sheets("Sheet5")
    Dim NotesArray As Variant
    Dim Sheet5Array As Variant
    Dim NotesRng As Variant
    Dim NotesArrayR As Long
    Dim LoopNotesArrayR As Long
    Dim Sheet5ArrayR As Long
With ws1
    NotesArrayR = .Cells(Rows.Count, "A").End(xlUp).Row - 2
    Set NotesRng = .Range("F3", .Range("F3").End(xlDown).End(xlToLeft))
    NotesArray = NotesRng
End With
     [COLOR=#ff0000]ReDim Sheet5Array(NotesArrayR, 2)[/COLOR]
     Sheet5ArrayR = 1
     
For LoopNotesArrayR = 1 To NotesArrayR
   If NotesArray(LoopNotesArrayR, 6) > 0 Then
      Sheet5Array(Sheet5ArrayR, 1) = NotesArray(LoopNotesArrayR, 1)
      Sheet5Array(Sheet5ArrayR, 2) = NotesArray(LoopNotesArrayR, 6)
      Sheet5ArrayR = Sheet5ArrayR + 1
   End If
Next

With ws5
    ws5.Activate
    Range("B3").Resize(UBound(Sheet5Array, 1), UBound(Sheet5Array, 2)) = Sheet5Array
End With
End Sub

Sorry it took so long but this has been a learning experience for me.

TotallyConfused


i get a error 7 code at the red text part and its pasting the input from A column on notes to the sheet5 in various locations
 
Upvote 0
i get a error 7 code at the red text part and its pasting the input from A column on notes to the sheet5 in various locations
Hello Countryboy69

I’m sorry you are having problems with the code.

To answer your question in post #23 , I ran the code in the general program module. Is that where you have it? I admit, I didn’t test the code in either of the sheet’s modules, though I wouldn’t think that would make a difference, but it could. If you are trying to run it in a sheet module, delete the code there and place it in the general module. Better yet, use a new test workbook. You don’t want to have the same code in both places as that could cause problems.

When I tested this, I put some text along both sides of the two columns in Sheet5, just to make sure nothing was spilling over into another column. As a final test, after running the code using your numbers, I added a couple of numbers at the end of yours, then ran it again just to make sure the code would accept additional rows. The required numbers fit into those two columns with no problems. I suspect the reason your numbers are scattered is that something went wrong with the way Sheet5Array is set up. I’m not familiar with error message code 7, in fact, I don’t remember ever seeing it. What does the brief text message along with the number say? That may give a clue as to what the problem is.

I noticed you are using a fairly recent version of Office and Windows. I have Office 365 with Windows 10, so I wouldn’t think there should be a compatibility problem, least none that I’ve heard of.

It’s well after midnight here, so I’m going to bed. I won’t be able to get back to this until this evening at the earliest. Maybe someone that is more experienced with VBA than I am will see this before I return and be able to offer a solution.

TotallyConfused
 
Last edited:
Upvote 0
So I added the code in to both the worksheet and modular (yes i deleted it before adding to another) well when i input my info this is what i get

Excel 2016 (Windows) 32 bit
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
1
JC 12/15/2018
MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY
INC BOX
D-box
Disputes
D.A.W
2
Barcode
Daughter B/C
W.A.D.
Full wt.
Empty wt.
Waste Wt.
Types
Destination
NPC/PSC
Notes
Full Wt.
Empty Wt.
Box #
Full Wt.
Full Wt.
Empty Wt.
Full Wt.
Empty Wt.
3
38031219
1250
620
630
B-25
4
38032525
1250
620
990
5
Sheet: NOTES

i need the info in from column J - R to also go to that line and add its self together

Excel 2016 (Windows) 32 bit
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
1
Barcode
Waste WT
40 S/l
20' S/l
B-25
Drum
Exelon
Other
DAW
EX metal
Metal
Time (in Min)
Customer
Total to Bin
Total to Inc
Total to Comp
Disputes
2
JC 12/15/2018
3
38031219
X
4
630
860
5
Sheet: DOWNTIME

this is what it looks like after my info is added
 
Upvote 0
Hello Countryboy69

I hope this is what you are looking for.

Code:
Option Base 1
Sub TransferData()
    Dim ws1 As Worksheet: Set ws1 = ThisWorkbook.Sheets("Notes")
    Dim ws5 As Worksheet: Set ws5 = ThisWorkbook.Sheets("Sheet5")
    Dim NotesArray As Variant
    Dim Sheet5Array As Variant
    Dim NotesRng As Variant
    Dim NotesArrayR As Long
    Dim LoopNotesArrayR As Long
    Dim Sheet5ArrayR As Long
With ws1
    NotesArrayR = .Cells(Rows.Count, "A").End(xlUp).Row - 2
    Set NotesRng = .Range("F3", .Range("F3").End(xlDown).End(xlToLeft))
    NotesArray = NotesRng
End With
     ReDim Sheet5Array(NotesArrayR, 2)
     Sheet5ArrayR = 1
     
For LoopNotesArrayR = 1 To NotesArrayR
   If NotesArray(LoopNotesArrayR, 6) > 0 Then
      Sheet5Array(Sheet5ArrayR, 1) = NotesArray(LoopNotesArrayR, 1)
      Sheet5Array(Sheet5ArrayR, 2) = NotesArray(LoopNotesArrayR, 6)
      Sheet5ArrayR = Sheet5ArrayR + 1
   End If
Next

With ws5
    ws5.Activate
    [COLOR=#ff0000]Range("B3").Resize(UBound(Sheet5Array, 1), UBound(Sheet5Array, 2)) = Sheet5Array[/COLOR]
End With
End Sub

Sorry it took so long but this has been a learning experience for me.

TotallyConfused

OK so now on the red text section i get Run-time error'1004': Application-defined or object-defined error
 
Upvote 0

Forum statistics

Threads
1,215,131
Messages
6,123,223
Members
449,091
Latest member
jeremy_bp001

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