VBA Form to format a sheet

mikechavarria

New Member
Joined
Apr 25, 2011
Messages
3
I am interested in an Excel VBA form that takes the values from two txt boxes and formats the sheet to show the matrix of the values. So if a person enters 32 in box 1 and 32 in box 2 it formats the sheet to have 32 rows with 32 columns and hides the rest.

How would this be coded in 1 button? For some reason my brain just doesn't want me to understand this!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Maybe like this

Code:
ActiveSheet.ScrollArea = Range(Cells(1, textbox1.Value), Cells(textbox2.Value, 10)).Address
 
Upvote 0
I pasted that code and changed it to have my textbox labels but still not working.

I found this code and it does what I need, Just how do I modify it to run on a specified sheet?

Code:
Private Sub cmdOK_Click()
If Not IsNumeric(Me.txtRows) Then
Me.txtRows.SetFocus
MsgBox "Please enter a valid number of rows"
Exit Sub
End If
If Me.txtRows < 1 Or Me.txtRows > Rows.Count Then
Me.txtRows.SetFocus
MsgBox "Please enter a valid number of rows"
Exit Sub
End If
If Not IsNumeric(Me.txtColumns) Then
Me.txtColumns.SetFocus
MsgBox "Please enter a valid number of columns"
Exit Sub
End If
If Me.txtColumns < 1 Or Me.txtColumns > Rows.Count Then
Me.txtColumns.SetFocus
MsgBox "Please enter a valid number of columns"
Exit Sub
End If
Application.ScreenUpdating = False
Cells.EntireRow.Hidden = False
Cells.EntireColumn.Hidden = False
Range(Cells(Me.txtRows + 1, 1), Cells(Rows.Count, 1)).EntireRow.Hidden = True
Range(Cells(1, Me.txtColumns + 1), Cells(1, Columns.Count)).EntireColumn.Hidden = True
Application.ScreenUpdating = True
Unload Me
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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