Decipher VBA code

lawi227

Board Regular
Joined
Mar 17, 2016
Messages
123
I have a workbook that has some VBA coding in it. I did not create the code (nor am I an expert in VBA). Can someone please tell me what these two module codes are doing:

<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #011993; background-color: #ffffff}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; background-color: #ffffff; min-height: 13.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}span.s1 {color: #000000}span.s2 {color: #011993}</style>Option Explicit


Dim ws As Worksheet




Sub Home_Range()


For Each ws In Worksheets
ws.Activate
ws.Range("A1").Select
Next ws
Worksheets(1).Activate
End Sub



-------------------------------------------


<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #011993; background-color: #ffffff}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; background-color: #ffffff; min-height: 13.0px}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px}span.s1 {color: #000000}span.s2 {color: #011993}</style>
Option Explicit
Dim ws As Worksheet


Sub szColumns()
For Each ws In Worksheets
If ws.Index >= 3 Then
ws.Activate
ws.Rows("1:2").RowHeight = 48
ws.Columns("A").ColumnWidth = 4.43
ws.Columns("B").ColumnWidth = 13.14
ws.Columns("C").ColumnWidth = 83.29
ws.Columns("D").ColumnWidth = 56.86
ws.Columns("E:G").ColumnWidth = 11.71
ws.Columns("H:I").ColumnWidth = 7.43
ws.Columns("J:L").ColumnWidth = 8.43
ws.Columns("M").ColumnWidth = 10#


End If

Next ws

End Sub
 

Some videos you may like

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).

AkaTrouble

Well-known Member
Joined
Dec 17, 2014
Messages
1,544
1st code just loops through worksheets and activates them

2nd code basically it is resizing the width of the columns for all worksheets after the third one
 
Last edited:

lawi227

Board Regular
Joined
Mar 17, 2016
Messages
123
Can I remove both codes and assume that nothing drastic will change? I'm not sure what it means to activate a worksheet in code 1..

1st code just loops through worksheets and activates them

2nd code basically it is resizing the width of the columns for all worksheets after the third one
 

AkaTrouble

Well-known Member
Joined
Dec 17, 2014
Messages
1,544
they may have been put there to be called from other macros to update sheets with formulas etc

you could rename them to Old_ at the begining of sub name and if after using the workbook they not needed and no errors then delete them

Code:
Sub Old_szColumns()
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,123,295
Messages
5,600,785
Members
414,405
Latest member
Zaurb

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
Top