+ Reply to Thread
Results 1 to 7 of 7

Create a combine macro with specidic functions

Hybrid View

  1. #1
    Registered User
    Join Date
    02-17-2013
    Location
    Bulgaria
    MS-Off Ver
    Excel 2007
    Posts
    45

    Create a combine macro with specidic functions

    Hi all,
    I`m trying to create a macro which will help me to save time at my work place.

    The codes that I wrote so far are:

    1. Insert rows based on specific value
    Sub test()
        Dim i, r As Range
        
        Set r = Sheets("Main").Columns(28).SpecialCells(-4123, 1)
     
        For i = r.Count To 1 Step -1
            r(i).Offset(1).Resize(r(i).Value-1).EntireRow.Insert
            
            With r(i).Offset(1, -27).Resize(r(i).Value)
                .Clear
                .Cells(0, 1).AutoFill .Cells(0, 1).Resize(r(i).Value + 1)
                .Cells(0, 2).AutoFill .Cells(0, 2).Resize(r(i).Value + 1)
                .Cells(0, 3).AutoFill .Cells(0, 3).Resize(r(i).Value + 1)
                .Cells(0, 4).AutoFill .Cells(0, 4).Resize(r(i).Value + 1)
                .Cells(0, 5).AutoFill .Cells(0, 5).Resize(r(i).Value + 1)
                .Cells(0, 6).AutoFill .Cells(0, 6).Resize(r(i).Value + 1)
                .Cells(0, 7).AutoFill .Cells(0, 7).Resize(r(i).Value + 1)
                .Cells(0, 8).AutoFill .Cells(0, 8).Resize(r(i).Value + 1)
                .Cells(0, 9).AutoFill .Cells(0, 9).Resize(r(i).Value + 1)
                .Cells(0, 10).AutoFill .Cells(0, 10).Resize(r(i).Value + 1)
                .Cells(0, 11).AutoFill .Cells(0, 11).Resize(r(i).Value + 1)
                .Cells(0, 12).AutoFill .Cells(0, 12).Resize(r(i).Value + 1)
                .Cells(0, 13).AutoFill .Cells(0, 13).Resize(r(i).Value + 1)
                .Cells(0, 14).AutoFill .Cells(0, 14).Resize(r(i).Value + 1)
                .Cells(0, 16).AutoFill .Cells(0, 16).Resize(r(i).Value + 1)
                
                 
         End With
        Next
    
    End Sub
    The problems here are:

    a) When I have value in range(r) = 0 the macro stops.
    What i want is, when I have value in this range 0 to skip inserting row below it.
    b) the information that is copying in the rows below the main row sholud be the same like the information in the main row.

    2.Transfer data
    Sub datatrans()
    
    Dim k As Long
    Dim i, j, n As Integer
    
    k = Worksheets("Main").Cells(Rows.Count, 20).End(xlUp).Row
    MsgBox (k)
    
     For i = 1 To k
      For j = 20 To 24
       n = n + 1
       Worksheets("Sub1").Cells(n, 1).Value = Worksheets("Main").Cells(i, j).Value
        
     Next j
    Next i
    End Sub
    3.Delete rows and transfer data

    Sub deleterows()
    
    Dim rng As Long
    Dim rng1 As Range
    
    rng = Worksheets("Sub1").Cells(Rows.Count, 1).End(xlUp).Row
    
    For i = rng To 1 Step -1
      If Cells(i, 1).Value = " " Or Cells(i, 1).Value = 0 Then
      Rows(i).EntireRow.Delete
      End If
     
     Next i
    
    
    Set rng1 = Worksheets("Sub1").Range("A1:A" & Worksheets("Sub1").Cells(Rows.Count, 1).End(xlUp).Row)
    
    Worksheets("Main").Range("O:O").ClearContents
    Worksheets("Main").Range("O1:O" & rng1.Rows.Count).Offset(1, 0).Value = rng1.Value
    End Sub
    So there is another question. Is it possible to combine all of these 3 macros in 1.

    I tried to do it with macro datatrans and delete rows but:

    For i = rng To 1 Step -1
      If Cells(i, 1).Value = " " Or Cells(i, 1).Value = 0 Then
      Rows(i).EntireRow.Delete
      End If
    this part of the macro did not work.


    If someone help me to do what I want.

    Thank you in advance

    Here is my example:
    Attached Files Attached Files
    Last edited by ExcelBG; 05-12-2017 at 02:53 AM.

  2. #2
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Create a combain macro with specidic functions

    Maybe

    Sub test()
    Application.ScreenUpdating = False
    lr = Range("A" & Rows.Count).End(xlUp).Row
        For x = lr To 1 Step -1
            If Cells(x, "AB").Value > 0 Then
                Range("A" & x + 1).EntireRow.Resize(Cells(x, "AB").Value).Insert
                Range("A" & x, "AB" & x + Cells(x, "AB").Value).FillDown
            End If
        Next
    End Sub
    Kind regards
    Leo

  3. #3
    Registered User
    Join Date
    02-17-2013
    Location
    Bulgaria
    MS-Off Ver
    Excel 2007
    Posts
    45

    Re: Create a combain macro with specidic functions

    Not maybe..

    It is working

    Thank u LeoTaxi.

    What about if I want to combine all the macros that I have in one?
    Last edited by ExcelBG; 05-11-2017 at 07:18 AM.

  4. #4
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Create a combine macro with specidic functions

    let me know what else has to be don
    not clear for me

    Kind regards
    Leo

  5. #5
    Registered User
    Join Date
    02-17-2013
    Location
    Bulgaria
    MS-Off Ver
    Excel 2007
    Posts
    45

    Re: Create a combine macro with specidic functions

    OK,

    I have 3 macros. Every macro is execute by button form control with assigned macro. I want to have only one button that will execute all the macros that I have. I tried this but one part of the macro didnt work:

    For i = rng To 1 Step -1
      If Cells(i, 1).Value = " " Or Cells(i, 1).Value = 0 Then
      Rows(i).EntireRow.Delete
      End If

  6. #6
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Create a combine macro with specidic functions

    Try

    Sub test()
    Application.ScreenUpdating = False
    lr = Range("A" & Rows.Count).End(xlUp).Row
        For x = lr To 1 Step -1
            If Cells(x, "AB").Value > 0 Then
                Range("A" & x + 1).EntireRow.Resize(Cells(x, "AB").Value).Insert
                Range("A" & x, "AB" & x + Cells(x, "AB").Value).FillDown
            Else
    	    Range("A" & x).EntireRow.Delete
    	End If
        Next
    End Sub
    Cheers
    Leo

  7. #7
    Registered User
    Join Date
    02-17-2013
    Location
    Bulgaria
    MS-Off Ver
    Excel 2007
    Posts
    45

    Re: Create a combine macro with specidic functions

    Thnak you LeoTaxi!

+ 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. create formulas and functions on excel
    By salgunaidi in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-23-2013, 05:05 PM
  2. Vlookup value and countif for 5 sheet combain
    By [email protected] in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-10-2013, 08:46 AM
  3. Replies: 2
    Last Post: 03-29-2013, 06:19 PM
  4. How to create 2 or more functions in one
    By stevesteve in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-29-2013, 03:02 AM
  5. create macro button to do certain functions then disable
    By ibrahim_zubi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-12-2013, 06:10 AM
  6. Create a formula using multiple if and functions?
    By mollyp in forum Excel General
    Replies: 1
    Last Post: 11-11-2009, 12:25 AM
  7. how to create my own functions??
    By anthropomorfic in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-09-2006, 06:10 PM
  8. [SOLVED] Create a dll with functions to excel
    By Rui Cruz in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-23-2006, 01:00 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