Auto Populate from dashboard to second spreadsheet

Joeclupis

Board Regular
Joined
Jun 18, 2016
Messages
63
I have a workbook with multiple sheets. I would like to learn how to set up my dashboard so that I can enter data on it, then have the data fill in the first open row on the spreadsheet. The spreadsheet has 17 columns of data with 2 blank columns after the 5th and 9th columns of information. We have over 3900 rows filled in now. I have googled for some help, but the code is above my head. I understand how to have a spreadsheet look at another for data, but not how to use one row on a spreadsheet to fill in a row on a different spreadsheet, and knowing that the row on the second spreadsheet will always change to the next empty row.

Joseph Carney
 
Roderick, I apologize for not replying last night. My day ended before your message came in. I went ahead and changed the mastersheet and receptor sheet names and columns to match what I have. Other than that I changed nothing. Running the code from the button didn't work, so I went back to VBA and hit the run command. below is the actual code that I have pasted in EXCEPT for the issued with setting the receptor = master. I made a comment there for you.

Code:
Option Compare Text 'ignore text caseSub copymasterdata()
Dim mastersh As Worksheet
Dim receptorsh1 As Worksheet
Dim lastrow1 As Long
Dim masterdatacells As String
Dim recept1cols As String
Dim masterunbound As Variant
Dim recept1unbound As Variant
Dim receptstr As String
Dim maststr As String
Dim i As Long




Set mastersh = Worksheets("Dashboard") 'set masterworksheet, change "Sheet1" to worksheet's actual name
Set receptorsh1 = Worksheets("Sheet2") 'set receptor sheet, change "Sheet2" to worksheet's actual name
masterdatacells = "A3, B3, C3, D3, E3, G3, H3, I3, J3, L3, M3, N3, O3, P3 Q3, R3, S3" 'these are the cells on the master sheet that will be copied [B][U]these columns are the actual ones set to transmit data, F and K are blank[/U][/B]
recept1cols = "A, B, C, D, E, G, H, I , J, L, M, N, O, P, Q, R, S" 'these the the columns to copy to on the receptor sheet [B][U]these columns are the actual ones set to receive data, F and K are blank[/U][/B]




'unfilter receptor sheet if filtered -- make for each receptor sheet next 3 lines, change numbers
If receptorsh1.AutoFilterMode Then
receptorsh1.Cells.AutoFilter
End If




'determine last row of each receptorsheet -- make for each receptor sheet change numbers
lastrow1 = receptorsh1.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row + 1
masterunbound = Split(masterdatacells, ",")
recept1unbound = Split(recept1cols, ",")
For i = LBound(masterunbound) To UBound(masterunbound)
receptstr = Trim(recept1unbound(i))
maststr = Trim(masterunbound(i))
[COLOR=#b22222]receptorsh1.Cells(lastrow1, receptstr) = mastersh.Range(maststr) '[B][U]debuger is stopping on this line I get a Run-time error '1004':  Method "Range' of object'_Worksheet' failed warning.  But if i acknowledge the error it will fill in the 'Sheet2' cells[/U][/B][/COLOR]
Next i












MsgBox "Copied", vbInformation, "CONFIRMATION"




End Sub
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I'm sorry I was out of the office for a long weekend. I will be able to look at this probably after 6pm EST.
 
Upvote 0
Roderick, I apologize for not replying last night. My day ended before your message came in. I went ahead and changed the mastersheet and receptor sheet names and columns to match what I have. Other than that I changed nothing. Running the code from the button didn't work, so I went back to VBA and hit the run command. below is the actual code that I have pasted in EXCEPT for the issued with setting the receptor = master. I made a comment there for you.

Code:
Option Compare Text 'ignore text caseSub copymasterdata()
Dim mastersh As Worksheet
Dim receptorsh1 As Worksheet
Dim lastrow1 As Long
Dim masterdatacells As String
Dim recept1cols As String
Dim masterunbound As Variant
Dim recept1unbound As Variant
Dim receptstr As String
Dim maststr As String
Dim i As Long




Set mastersh = Worksheets("Dashboard") 'set masterworksheet, change "Sheet1" to worksheet's actual name
Set receptorsh1 = Worksheets("Sheet2") 'set receptor sheet, change "Sheet2" to worksheet's actual name
masterdatacells = "A3, B3, C3, D3, E3, G3, H3, I3, J3, L3, M3, N3, O3, P3 Q3, R3, S3" 'these are the cells on the master sheet that will be copied [B][U]these columns are the actual ones set to transmit data, F and K are blank[/U][/B]
recept1cols = "A, B, C, D, E, G, H, I , J, L, M, N, O, P, Q, R, S" 'these the the columns to copy to on the receptor sheet [B][U]these columns are the actual ones set to receive data, F and K are blank[/U][/B]




'unfilter receptor sheet if filtered -- make for each receptor sheet next 3 lines, change numbers
If receptorsh1.AutoFilterMode Then
receptorsh1.Cells.AutoFilter
End If




'determine last row of each receptorsheet -- make for each receptor sheet change numbers
lastrow1 = receptorsh1.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row + 1
masterunbound = Split(masterdatacells, ",")
recept1unbound = Split(recept1cols, ",")
For i = LBound(masterunbound) To UBound(masterunbound)
receptstr = Trim(recept1unbound(i))
maststr = Trim(masterunbound(i))
[COLOR=#b22222]receptorsh1.Cells(lastrow1, receptstr) = mastersh.Range(maststr) '[B][U]debuger is stopping on this line I get a Run-time error '1004':  Method "Range' of object'_Worksheet' failed warning.  But if i acknowledge the error it will fill in the 'Sheet2' cells[/U][/B][/COLOR]
Next i












MsgBox "Copied", vbInformation, "CONFIRMATION"




End Sub

Note you have no comma between P3 and Q3, that is causing the error
 
Upvote 0
Added new stuff to handle potential errors like the missing comma. Use this code instead:

Code:
Option Compare Text 'ignore text case
Function ValidAddress(strAddress As String) As Boolean
    Dim r As Range
    On Error Resume Next
    Set r = Worksheets(1).Range(strAddress)
    If Not r Is Nothing Then ValidAddress = True
End Function
Sub copymasterdata()
Dim mastersh As Worksheet
Dim receptorsh1 As Worksheet
Dim lastrow1 As Long
Dim masterdatacells As String
Dim recept1cols As String
Dim masterunbound As Variant
Dim recept1unbound As Variant
Dim receptstr As String
Dim maststr As String
Dim i As Long
Dim errmsg As String


Set mastersh = Worksheets("Sheet1") 'set masterworksheet, change "Sheet1" to worksheet's actual name
Set receptorsh1 = Worksheets("Sheet2") 'set receptor sheet, change "Sheet2" to worksheet's actual name
masterdatacells = "A3, B3, C3, D3, E3, G3, H3, I3, J3, L3, M3, N3, O3, P3, Q3, R3, S3" 'these are the cells on the master sheet that will be copied
recept1cols = "A, B, C, D, E, G, H, I, J, L, M, N, O, P, Q, R, S" 'these the the columns to copy to on the receptor sheet


'check for valid addresses and matching receptor1cols
masterunbound = Split(masterdatacells, ",")
recept1unbound = Split(recept1cols, ",")
If UBound(masterunbound) <> UBound(recept1unbound) Then
MsgBox "The master columns and the receptor1 columns aren't the same count." & vcbr & " Perhaps there is a missing comma", vbCritical, "ALERT"
Exit Sub
End If
For i = LBound(masterunbound) To UBound(masterunbound)
If ValidAddress(Trim(masterunbound(i))) = False Then
If errmsg = "" Then
errmsg = Trim(masterunbound(i))
Else
errmsg = errmsg & vbCr & Trim(masterunbound(i))
End If
End If
Next i
If errmsg <> "" Then
MsgBox "The following master cell addresses are invalid (may require comma):" & vbCr & "-----------------------" & vbCr & errmsg, vbCritical, "ALERT"
Exit Sub
End If




'unfilter receptor sheet if filtered -- make for each receptor sheet next 3 lines, change numbers
If receptorsh1.AutoFilterMode Then
receptorsh1.Cells.AutoFilter
End If


'determine last row of each receptorsheet -- make for each receptor sheet change numbers
lastrow1 = receptorsh1.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row + 1
masterunbound = Split(masterdatacells, ",")
recept1unbound = Split(recept1cols, ",")
For i = LBound(masterunbound) To UBound(masterunbound)
receptstr = Trim(recept1unbound(i))
maststr = Trim(masterunbound(i))
receptorsh1.Cells(lastrow1, receptstr) = mastersh.Range(maststr)
Next i






MsgBox "Copied", vbInformation, "CONFIRMATION"


End Sub
 
Upvote 0
Better yet, this one has a clearer variable that you can set to clear the previous master sheet entries.

Code:
Option Compare Text 'ignore text case
Function ValidAddress(strAddress As String) As Boolean
    Dim r As Range
    On Error Resume Next
    Set r = Worksheets(1).Range(strAddress)
    If Not r Is Nothing Then ValidAddress = True
End Function
Sub copymasterdata()
Dim mastersh As Worksheet
Dim receptorsh1 As Worksheet
Dim lastrow1 As Long
Dim masterdatacells As String
Dim recept1cols As String
Dim masterunbound As Variant
Dim recept1unbound As Variant
Dim receptstr As String
Dim maststr As String
Dim i As Long
Dim errmsg As String
Dim clearer As Long


Set mastersh = Worksheets("Sheet1") 'set masterworksheet, change "Sheet1" to worksheet's actual name
Set receptorsh1 = Worksheets("Sheet2") 'set receptor sheet, change "Sheet2" to worksheet's actual name
masterdatacells = "A3, B3, C3, D3, E3, G3, H3, I3, J3, L3, M3, N3, O3, P3, Q3, R3, S3" 'these are the cells on the master sheet that will be copied
recept1cols = "A, B, C, D, E, G, H, I, J, L, M, N, O, P, Q, R, S" 'these the the columns to copy to on the receptor sheet
clearer = 0 'set to 1 to clear the master sheet entries after each run




'check for valid addresses and matching receptor1cols
masterunbound = Split(masterdatacells, ",")
recept1unbound = Split(recept1cols, ",")
If UBound(masterunbound) <> UBound(recept1unbound) Then
MsgBox "The master columns and the receptor1 columns aren't the same count." & vcbr & " Perhaps there is a missing comma", vbCritical, "ALERT"
Exit Sub
End If
For i = LBound(masterunbound) To UBound(masterunbound)
If ValidAddress(Trim(masterunbound(i))) = False Then
If errmsg = "" Then
errmsg = Trim(masterunbound(i))
Else
errmsg = errmsg & vbCr & Trim(masterunbound(i))
End If
End If
Next i
If errmsg <> "" Then
MsgBox "The following master cell addresses are invalid (may require comma):" & vbCr & "-----------------------" & vbCr & errmsg, vbCritical, "ALERT"
Exit Sub
End If




'unfilter receptor sheet if filtered -- make for each receptor sheet next 3 lines, change numbers
If receptorsh1.AutoFilterMode Then
receptorsh1.Cells.AutoFilter
End If


'determine last row of each receptorsheet -- make for each receptor sheet change numbers
lastrow1 = receptorsh1.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row + 1
masterunbound = Split(masterdatacells, ",")
recept1unbound = Split(recept1cols, ",")
For i = LBound(masterunbound) To UBound(masterunbound)
receptstr = Trim(recept1unbound(i))
maststr = Trim(masterunbound(i))
receptorsh1.Cells(lastrow1, receptstr) = mastersh.Range(maststr)
'clear previous master sheet entries if clearer set to 1
If clearer = 1 Then
mastersh.Range(maststr) = ""
End If
Next i






MsgBox "Copied", vbInformation, "CONFIRMATION"


End Sub
 
Upvote 0
To allow it to add to other sheets besides receptor1, simply follow the same concepts and add into the code receptor2 receptor3 and so on.
 
Upvote 0
This one has a feature that allows you to set the UID, unique id that will check and not add duplicates to the receptor sheet.

Code:
Option Compare Text 'ignore text case
Function ValidAddress(strAddress As String) As Boolean
    Dim r As Range
    On Error Resume Next
    Set r = Worksheets(1).Range(strAddress)
    If Not r Is Nothing Then ValidAddress = True
End Function
Sub copymasterdata()
Dim mastersh As Worksheet
Dim receptorsh1 As Worksheet
Dim lastrow1 As Long
Dim masterdatacells As String
Dim recept1cols As String
Dim masterunbound As Variant
Dim recept1unbound As Variant
Dim receptstr As String
Dim maststr As String
Dim i As Long
Dim errmsg As String
Dim clearer As Long
Dim uidcol As String
Dim dupes As String


Set mastersh = Worksheets("Sheet1") 'set masterworksheet, change "Sheet1" to worksheet's actual name
Set receptorsh1 = Worksheets("Sheet2") 'set receptor sheet, change "Sheet2" to worksheet's actual name
masterdatacells = "A3, B3, C3, D3, E3, G3, H3, I3, J3, L3, M3, N3, O3, P3, Q3, R3, S3" 'these are the cells on the master sheet that will be copied
recept1cols = "A, B, C, D, E, G, H, I, J, L, M, N, O, P, Q, R, S" 'these the the columns to copy to on the receptor sheet
clearer = 0 'set to 1 to clear the master sheet entries after each run
uidcol = "" 'set to column letter of uid. Should also be first letter in recept1cols even if not in order.




'check for valid addresses and matching receptor1cols
masterunbound = Split(masterdatacells, ",")
recept1unbound = Split(recept1cols, ",")
If UBound(masterunbound) <> UBound(recept1unbound) Then
MsgBox "The master columns and the receptor1 columns aren't the same count." & vcbr & " Perhaps there is a missing comma", vbCritical, "ALERT"
Exit Sub
End If
For i = LBound(masterunbound) To UBound(masterunbound)
If ValidAddress(Trim(masterunbound(i))) = False Then
If errmsg = "" Then
errmsg = Trim(masterunbound(i))
Else
errmsg = errmsg & vbCr & Trim(masterunbound(i))
End If
End If
Next i
If errmsg <> "" Then
MsgBox "The following master cell addresses are invalid (may require comma):" & vbCr & "-----------------------" & vbCr & errmsg, vbCritical, "ALERT"
Exit Sub
End If




'unfilter receptor sheet if filtered -- make for each receptor sheet next 3 lines, change numbers
If receptorsh1.AutoFilterMode Then
receptorsh1.Cells.AutoFilter
End If


'determine last row of each receptorsheet -- make for each receptor sheet change numbers
lastrow1 = receptorsh1.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row + 1
masterunbound = Split(masterdatacells, ",")
recept1unbound = Split(recept1cols, ",")
For i = LBound(masterunbound) To UBound(masterunbound)
receptstr = Trim(recept1unbound(i))
maststr = Trim(masterunbound(i))


'do uid check. Set UIDCOL at beginning of code
If Trim(uidcol) <> "" Then
If receptstr = uidcol Then
If IsError(Application.Match(mastersh.Range(maststr), receptorsh1.Range(receptstr & ":" & receptstr), 0)) = False Then
dupes = mastersh.Range(maststr)
GoTo ender:
Exit Sub
End If
End If
End If
receptorsh1.Cells(lastrow1, receptstr) = mastersh.Range(maststr)
If clearer = 1 Then
mastersh.Range(maststr) = ""
End If
Next i


ender:
If dupes <> "" Then
dupes = "Duplicate UID not added:" & vbCr & "------------------" & vbCr & dupes
Else
dupes = "Copied"
End If
MsgBox dupes, vbInformation, "CONFIRMATION"


End Sub
 
Last edited:
Upvote 0
Roderick,

I have come up against a small issue. I have two columns on the receptor sheet that have formulas in them. I am trying to find code that would look in the previous row for the formula and apply it to the current row. I did find this:

Code:
' Copy formula from cell aboveRows(Selection.Row - 1).Copy
Rows(Selection.Row).Insert Shift:=xlDown

but I don't think it is quite what I am looking for, it actually copies the entire row. Is there some where that you could point me towards so that I can get the code and try to learn how, so that I don't have to keep coming back to the forum and begging?

Thanks
 
Upvote 0
Roderick,

I have come up against a small issue. I have two columns on the receptor sheet that have formulas in them. I am trying to find code that would look in the previous row for the formula and apply it to the current row. I did find this:

Code:
' Copy formula from cell aboveRows(Selection.Row - 1).Copy
Rows(Selection.Row).Insert Shift:=xlDown

but I don't think it is quite what I am looking for, it actually copies the entire row. Is there some where that you could point me towards so that I can get the code and try to learn how, so that I don't have to keep coming back to the forum and begging?

Thanks

Hi there. Why not just leave those formulas out of the recept1cols = "A, B, C, D, E, G, H, I, J, L, M, N, O, P, Q, R, S"? Or maybe I'm misunderstanding? Re-reading it sounds like you just want it to automatically drag the formula down to the last populated row???

As for one site to train you, most people who learn code of any sort don't do so by going to school or reading a book. They learn by just getting in there and trying different things that they have learned here and there.

Back to the issue, you will need another macro that loops through the worksheet and dragging down columns with formulas.

Look into this code snippet:
Code:
.Range("A2:A15").FillDown
This drags A2 to A15
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,301
Members
449,078
Latest member
nonnakkong

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