Results 1 to 10 of 11

Thread: Excel Macro to populate the values in the required cells

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    Quote Originally Posted by Excel Fox View Post
    Try this from a module or workbook code module

    Code:
    Sub ExcelFox()
        Dim wks As Worksheet
        For Each wks In ThisWorkbook.Worksheets
            If Right(UCase(wks.Name), 1) = "P" Then
                With wks
                    .Range("G9:J" & .Cells(.Rows.Count, 1).End(xlUp).Row).Value = _
                        Array(1, "Minutes", -4431, #1/1/2013#)
                End With
            ElseIf Right(UCase(wks.Name), 1) = "S" Then
                With wks
                    .Range("G9:J" & .Cells(.Rows.Count, 1).End(xlUp).Row).Value = _
                        Array(0, "Minutes", -4431, #1/1/2013#)
                End With
            End If
        Next wks
    End Sub
    You can shorten the above code to this...

    Code:
    Sub ExcelFox()
      Dim wks As Worksheet
      For Each wks In ThisWorkbook.Worksheets
        If wks.Name Like "*[PS]" Then wks.Range("G9:J" & wks.Cells(Rows.Count, "A").End( _
               xlUp).Row) = Array(Abs(wks.Name Like "*P"), "Minutes", -4431, #1/1/2013#)
      Next
    End Sub
    Note: I wrapped the long line of code using the line continuation character for neatness of display, but you can unwrap that line if you want.
    Last edited by Rick Rothstein; 11-02-2013 at 12:11 PM.

Similar Threads

  1. populate default values in cell of a csv file
    By dhivya.enjoy in forum Excel Help
    Replies: 2
    Last Post: 10-23-2013, 12:59 PM
  2. Replies: 12
    Last Post: 07-26-2013, 07:39 AM
  3. VBA Program to Compare 4 Columns in Excel (Required)
    By vijaysram in forum Excel Help
    Replies: 11
    Last Post: 06-26-2013, 10:53 AM
  4. Unmerge Cells and Fill with Duplicate Values
    By princ_wns in forum Excel Help
    Replies: 3
    Last Post: 10-09-2012, 07:36 AM

Posting Permissions

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