Transpose Macro on a Button

MottPott

New Member
Joined
Aug 24, 2022
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
So I am looking to make a button that when pressed, the macro will cut the values/ words (not the formatting, as this column has drop down lists) from worksheet 1 (Data Entry), and paste them onto worksheet 2 (Locked) in rows.
I don't want it overriding the existing rows in worksheet 2, rather I want it to make a list. So each time it pastes the transposed row onto a new/empty line.

ie. Cut the values/ words from Column B or Range B2:B11. then transpose paste the values on worksheet 2 in a Row, each time to a new/ empty row.

I am struggling to get this all to work, and would like any help I can get.

On a side note, is it possible to lock the worksheet 2, or prevent people from viewing it. As it will be collating information from the worksheet 1 survey.
I know I can lock the worksheet and prevent anyone from editing it, however I'd also like to make it so no one can see/ view its contents.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi,
here is a sample code for you.
VBA Code:
Sub Transpose()
    Dim rFrom As Range, rTo As Range
    'If you want to make the range variable like a selection, change this to "Selection".
    Set rFrom = Sheets("Sheet1").Range("B2: B11")
    Set rTo = Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Offset(1)
    rTo.Resize(, rFrom.Rows.Count).Value = Application.Transpose(rFrom.Value)
End Sub
For hiding worksheet2, you can set xlSheetVeryHidden to the visible property from code/VBE so that no one can make it visible/editable from Excel.

VBA Code:
Worksheets("Sheet2").Visible = xlSheetVeryHidden
 
Upvote 0
Hi,
here is a sample code for you.
VBA Code:
Sub Transpose()
    Dim rFrom As Range, rTo As Range
    'If you want to make the range variable like a selection, change this to "Selection".
    Set rFrom = Sheets("Sheet1").Range("B2: B11")
    Set rTo = Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Offset(1)
    rTo.Resize(, rFrom.Rows.Count).Value = Application.Transpose(rFrom.Value)
End Sub
For hiding worksheet2, you can set xlSheetVeryHidden to the visible property from code/VBE so that no one can make it visible/editable from Excel.

VBA Code:
Worksheets("Sheet2").Visible = xlSheetVeryHidden
Awesome, I love it. Thank you!!!

It copies/ transposes it all, thank you.

When I tried adding a clear contents line into it, I couldn't get it to work. I want to clear the content of the column after (Just the words, not the formatting).
 
Upvote 0
When I tried adding a clear contents line into it, I couldn't get it to work. I want to clear the content of the column after (Just the words, not the formatting).
Glad it helps! To clear the content of the column, just add the following line above End Sub.
VBA Code:
rFrom.ClearContents
 
Upvote 0

Forum statistics

Threads
1,214,948
Messages
6,122,420
Members
449,083
Latest member
Ava19

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