Results 1 to 9 of 9

Thread: Divide Rest of the Columns using Column A values

  1. #1
    Member
    Join Date
    Aug 2011
    Posts
    54
    Rep Power
    13

    Divide Rest of the Columns using Column A values

    Hi All,

    I have a complex query.

    In the excel sheet column A values to be divided with rest of the columns.

    Example Cell A1 value to be used to dived rest of the visible rows like B1, C1 D1,etc

    Columns and row are not fixed and it is dynamic.

    for the ready reference i have attached sample workbook which has sheet1 which has input value and sheet 2 which has result.

    Request to help if this can be done VBA code.

    Regards,

    Prabhu
    Attached Files Attached Files

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    Hi

    try

    Code:
    Option Explicit
    
    Sub kTest()
        
        Dim r   As Long, c  As Long
        Dim ColA, d, Dest As Range
        
        With Worksheets("Sheet1")
            r = .Range("a" & .Rows.Count).End(xlUp).Row
            c = .Cells(1, .Columns.Count).End(xlToLeft).Column
            ColA = .Range("a2:a" & r).Value2
            d = .Range("b2", .Cells(r, c)).Value2
            Set Dest = .Range("b2")
        End With
        
        If IsArray(ColA) Then
            If IsArray(d) Then
                For r = 1 To UBound(ColA, 1)
                    For c = 1 To UBound(d, 2)
                        If ColA(r, 1) = 0 Then
                            d(r, c) = "=iferror(" & d(r, c) & "/" & ColA(r, 1) & ",0)"
                        Else
                            d(r, c) = "=" & d(r, c) & "/" & ColA(r, 1)
                        End If
                    Next
                Next
                Dest.Resize(UBound(d, 1), UBound(d, 2)).Value2 = d
            End If
        End If
        
    End Sub
    Last edited by Admin; 12-17-2015 at 02:40 PM. Reason: code edited
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  3. #3
    Member
    Join Date
    Aug 2011
    Posts
    54
    Rep Power
    13
    Thanks!

    I could not run the macro,below code shows as run time error '1004' Application-defined or object -defined error.


    Dest.Resize(UBound(d, 1), UBound(d, 2)).Value2 = d

  4. #4
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    I have edited the above code.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  5. #5
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    12
    or

    Code:
    Sub M_snb()
       Sheet2.Cells(20, 1).Resize(9, 4) = [index(if(column(A2:D2)=1,sheet1!A2:A10,round(sheet1!A2:D10/sheet1!A2:A10,0)),)]
    End Sub
    Last edited by snb; 12-17-2015 at 08:13 PM.

  6. #6
    Member
    Join Date
    Aug 2011
    Posts
    54
    Rep Power
    13
    Hi Admin,

    Still i am getting same error

  7. #7
    Member
    Join Date
    Aug 2011
    Posts
    54
    Rep Power
    13
    Quote Originally Posted by Prabhu View Post
    Hi Admin,

    Still i am getting same error
    request your help to resolve the error.

  8. #8
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    12
    Did you overlook #5 ?

  9. #9
    Member
    Join Date
    Aug 2011
    Posts
    54
    Rep Power
    13
    Quote Originally Posted by snb View Post
    Did you overlook #5 ?
    Yes,

    with the same format of Sheet 1 along with the formulas in cell( instead of value format) like "=149/6" will solve the purpose.

    also the row and column are flexible number of row used to change every time.

    the solution provide by the admin is working for the 1st line only and then "Dest.Resize(UBound(d, 1), UBound(d, 2)).Value2 = d" code highlighted as error.

    if you help to resolve the error also fine for me.

    Thanks for the support.

Similar Threads

  1. Concatenating your Balls
    By DocAElstein in forum Excel Help
    Replies: 26
    Last Post: 10-13-2014, 02:07 PM
  2. Replies: 10
    Last Post: 02-18-2014, 01:34 PM
  3. Replies: 6
    Last Post: 07-26-2013, 11:42 AM
  4. Replies: 10
    Last Post: 05-23-2013, 12:30 PM
  5. Replies: 4
    Last Post: 04-05-2013, 12:08 PM

Posting Permissions

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