+ Reply to Thread
Results 1 to 3 of 3

VBA to run across all worksheet

  1. #1
    Registered User
    Join Date
    07-20-2015
    Location
    ireland
    MS-Off Ver
    2007
    Posts
    4

    VBA to run across all worksheet

    Hi All, I am new here and in VBA MAcro in excel 2007 but manage to create a code to run in a single worksheet. Is there anyone that can help to make this code/macro to run across all worksheets?? If so , many thanks in advance...below is my vba code /macro:

    Sub transpose()
    Application.ScreenUpdating = False
    ActiveSheet.UsedRange.Copy
    Sheets.Add After:=Sheets(Sheets.Count)
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=True

    DateRowStart = 4 'Row on which the actual data starts
    DateRowEnd = 51 'Row where the data ends for each column
    ColStart = 2 'Column number of the first meter
    NumDays = 1000 'Number of Days/Columns to cycle through


    PastePoint = DateRowEnd + 1

    For i = 0 To NumDays

    Cells(3, ColStart + 1 + i).Select
    Selection.Cut
    Cells(PastePoint, 1).Select
    ActiveSheet.Paste

    Range(Cells(DateRowStart, ColStart + 1 + i), Cells(DateRowEnd, ColStart + 1 + i)).Select
    Selection.Cut
    Cells(PastePoint, 2).Select
    ActiveSheet.Paste

    PastePoint = PastePoint + 48

    Next i

    Range(Cells(1, 3), Cells(3, NumDays + 3)).Clear

    Columns("B:B").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Selection.NumberFormat = "dd/mm/yyyy hh:mm"

    Range("C3").Cut Destination:=Range("A4")
    Range("B4").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]+TIME(0,30,0)"
    Range("B5").Select
    ActiveCell.FormulaR1C1 = "=R[-1]C+TIME(0,30,0)"
    Columns("A:B").EntireColumn.AutoFit

    Dim lastRow As Long
    lastRow = Range("C" & Rows.Count).End(xlUp).Row
    Range("B5").AutoFill Destination:=Range("B5:B" & lastRow)

    Rows("2:3").Select
    Selection.Delete
    [B1].Value = "Timestamp "
    Columns("B:B").Select
    Selection.Copy
    Columns("B:B").Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
    xlNone, SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
    Columns("B:B").ColumnWidth = 18
    Columns("C:C").ColumnWidth = 12.44
    Columns("A:A").Select
    Selection.EntireColumn.Hidden = True

    End sub

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,510

    Re: VBA to run across all worksheet

    Might be better to provide a sample workbook and describe what you are trying to do, and the expected output, rather than to try to tweak a recorded macro.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Valued Forum Contributor
    Join Date
    05-11-2013
    Location
    Wales
    MS-Off Ver
    Excel 2010
    Posts
    586

    Re: VBA to run across all worksheet

    Not sure if this is what you are after but check out the following link.

    https://support.office.com/en-nz/art...0-6e4c3f5ee566

    Regards
    peterrc

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Data linking from one worksheet to another worksheet without alteration in 1st worksheet
    By paradise2sr in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-05-2015, 01:42 AM
  2. Replies: 3
    Last Post: 05-26-2014, 02:21 AM
  3. [SOLVED] Macro to Copy Master Worksheet create and paste in new auto named worksheet
    By TheRealLethality in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-15-2014, 12:46 AM
  4. [SOLVED] Copy data from a worksheet and paste to worksheet with a similar worksheet name
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-21-2012, 04:02 AM
  5. Copy data from a worksheet and paste to worksheet with a similar worksheet name
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-21-2012, 02:49 AM
  6. Replies: 3
    Last Post: 10-16-2012, 09:02 AM
  7. Replies: 1
    Last Post: 08-29-2012, 07:11 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1