Master Worksheet with command Button to update data

MajorK

New Member
Joined
Jan 22, 2018
Messages
3
I need to increment the column index in the summary sheet each time I run the code or click the command button.
The Below code is able to do the job 1 time.
When I click the command button the Date should be added in the header, then the result of each sheet (row by row).
The result should look like the summary sheet in the attached picture. First time we run the macro: data displayed in Column B Second time: in Column C etc,..
rDmDj.jpg

<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; white-space: inherit;"> Sub Worksheets_Summary()
Dim OldSheet As Worksheet
Dim NewSheet As Worksheet
Dim Cell As Range
Dim ColNum As Integer
Dim RwNum As Long
Dim book As Workbook
Set book = ThisWorkbook
Set NewSheet = book.Worksheets("Summary")
NewSheet
.Rows("2:" & NewSheet.Rows.Count).Clear

RwNum
= 1

For Each OldSheet In book.Worksheets
If OldSheet.Name <> "Summary" Then
Range
("B1").Value = Now() 'Change B1
ColNum
= 1
RwNum
= RwNum + 1

NewSheet
.Cells(RwNum, 1).Formula _
= "=HYPERLINK(""#""&CELL(""address"",'" & OldSheet.Name & "'!A1)," _
& """" & OldSheet.Name & """)"

For Each Cell In OldSheet.Range("B11")
ColNum
= ColNum + 1
NewSheet
.Cells(RwNum, ColNum).Formula = _
"='" & OldSheet.Name & "'!" & Cell.Address(False, False)
Next Cell

End If
Next OldSheet

NewSheet
.UsedRange.Columns.AutoFit


End With
End Sub</code>Please Help!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
have modified your code as below. Have commented added or changed and highlighted them in red so you can see. also commented out a line of code as I couldn't figure out its purpose.

Code:
Sub Worksheets_Summary()
Dim OldSheet As Worksheet
Dim NewSheet As Worksheet
Dim Cell As Range
Dim ColNum As Integer
Dim RwNum As Long
Dim book As Workbook
[COLOR=#ff0000]Dim LastCol As Integer[/COLOR] [COLOR=#008000]'added[/COLOR]
Set book = ThisWorkbook
Set NewSheet = book.Worksheets("Summary")
[COLOR=#ff0000]'NewSheet.Rows("2:" & NewSheet.Rows.Count).Clear[/COLOR] '[COLOR=#008000]couldn't figure the purpose[/COLOR]
RwNum = 1
[COLOR=#ff0000]LastCol = Cells(1, Columns.Count).End(xlToLeft).Column + 1[/COLOR] [COLOR=#008000]'added[/COLOR]


For Each OldSheet In book.Worksheets
If OldSheet.Name <> "Summary" Then
[COLOR=#ff0000]Cells(1, LastCol)[/COLOR].Value = Now() 'Change B1 [COLOR=#008000]'CHANGED[/COLOR]
ColNum = 1
RwNum = RwNum + 1


NewSheet.Cells(RwNum, 1).Formula _
= "=HYPERLINK(""#""&CELL(""address"",'" & OldSheet.Name & "'!A1)," _
& """" & OldSheet.Name & """)"


For Each Cell In OldSheet.Range("B11")
ColNum = ColNum + 1
NewSheet.Cells(RwNum, [COLOR=#ff0000]LastCol[/COLOR]).Formula = _
"='" & OldSheet.Name & "'!" & Cell.Address(False, False) [COLOR=#008000]'CHANGED[/COLOR]
Next Cell


End If
Next OldSheet


NewSheet.UsedRange.Columns.AutoFit


'End With
End Sub

Hope this helps, don't forget to test it on a copy workbook first

Coops
 
Upvote 0
It Worked! 1 additional question, what need to be done to switch column and rows?

Not sure what you mean. Why do you need to switch columns and rows? from your first post this simply adds the update to the next empty column?
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,217
Members
452,619
Latest member
Shiv1198

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