+ Reply to Thread
Results 1 to 16 of 16

Counting used cells in forms not working in different places

  1. #1
    Registered User
    Join Date
    10-07-2018
    Location
    jeddah
    MS-Off Ver
    2007
    Posts
    9

    Counting used cells in forms not working in different places

    HI everyone
    I'm new in vba excel but trying to use it to help me in my job , so I already create one to save my time by copy paste data from one excel sheet and fill it in another excel sheet designed forms.
    It's working great, till last code for counting total used rows in each form , It's working with first form but forms below what every their quantity not working I couldn't figure out

    here is the code for first form which is working fine

    Set rngk = ws2.Range("ae45")
    fil = ws2.Range("L50:L68").Cells.SpecialCells(xlCellTypeConstants).Count
    rngk.Value = "NUMBER OF DRAWINGS SPECIFY ON THIS SHEET " & fil & ")"

    and here is the second one to do the same in below forms

    Set rngk1 = ws2.Range("ae45").Offset(g * a, 0)
    fil1 = ws2.Range("L50:L68").Offset(i * a, 0).Cells.SpecialCells(xlCellTypeConstants).Count

    rngk1.Value = "NUMBER OF DRAWINGS ON THIS SHEET " & fil1 & ")"

    i=18
    g=36
    a= 1 to cnt ( which is no of forms to be created)INFO.png

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Counting used cells in forms not working in different places

    Change the i to a g

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Counting used cells in forms not working in different places

    Hi, welcome to the forum.
    I suggest you use code tags around posted code to make the reading of this code easier (read the forum rules to see how that is done)
    If your first form works fine, what's the difference between the other one? What doesn't work.
    A picture does not work to help.
    I suggest a file with some dummy data with what you have and what you want to will help us understand your question and maybe help you
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  4. #4
    Registered User
    Join Date
    10-07-2018
    Location
    jeddah
    MS-Off Ver
    2007
    Posts
    9

    Re: Counting used cells in forms not working in different places

    Not working , because it must i not g INFO1.png

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Counting used cells in forms not working in different places

    Quote Originally Posted by zodiac77 View Post
    Not working , because it must i not g Attachment 593078
    That's hardly descriptive. Did you try it with g ?

    If it does not work, then I don't understand the nature of your data.

  6. #6
    Registered User
    Join Date
    10-07-2018
    Location
    jeddah
    MS-Off Ver
    2007
    Posts
    9

    Re: Counting used cells in forms not working in different places

    OK
    I WILL POST MY FULL CODE HERE


    Sub TRSFTSTmossab()

    Dim rng11 As Range
    Dim rng12 As Range
    Dim rng13 As Range
    Dim rng14 As Range
    Dim lastrow As Long

    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Set ws1 = Worksheets("sht1")
    Set ws2 = Worksheets("sht7")

    Dim rng5 As Range
    Dim rng6 As Range
    Dim rng7 As Range
    Dim rng8 As Range
    Dim rng20 As Range
    Dim rnge21 As Range


    Dim i As Integer
    Dim a As Integer
    Dim Y As Integer
    Dim g As Integer
    Dim x As Integer
    Dim cnt As Long
    Dim cnt1 As Long
    Dim cnt2 As Long
    Dim cnt3 As Long


    Dim rngf As Range
    Dim rngh As Range
    Dim rngm As Range
    Dim rngn As Range
    Dim rngo As Range
    Dim rngp As Range
    Dim rngy As Range
    Dim rngw As Range


    Set rngh = ws2.Range("i13:k13")
    Set rngf = ws2.Range("i14:k32")
    Set rngm = ws2.Range("f14:h32")
    Set rngn = ws2.Range("c14:e32")


    Set rngy = ws2.Range("a13:b13")
    Set rngw = ws2.Range("a14:b32")

    Set rngo = ws2.Range("l13:al13")
    Set rngp = ws2.Range("l14:al32")




    Dim tot As Long

    Dim fil As Long
    Dim rngk As Range


    Set rng5 = ws1.Range("a19:a37")
    Set rng6 = ws1.Range("b19:b37")
    Set rng7 = ws1.Range("c19:c37")
    Set rng8 = ws1.Range("d19:d37")
    Set rng20 = ws1.Range("e19:e37")



    Set rng11 = ws2.Range("C50:E68")
    Set rng12 = ws2.Range("F50:H68")
    Set rng13 = ws2.Range("I50:K68")
    Set rng14 = ws2.Range("L50:AL68")
    Set rng22 = ws2.Range("A50:B68")

    i = 18
    Y = 19

    Application.ScreenUpdating = False

    With ws1
    tot = .Cells(.Rows.Count, "A").End(xlUp).Row

    End With

    cnt1 = ws1.Range("A1:A18").Rows.Count
    cnt2 = tot - cnt1
    cnt = cnt2 / Y
    If cnt < 1 Then
    cnt = 1 + cnt
    cnt = Fix(cnt)
    Else

    End If



    rng5.Copy
    rng11.PasteSpecial

    rng6.Copy
    rng12.PasteSpecial

    rng7.Copy
    rng13.PasteSpecial

    rng8.Copy
    rng14.PasteSpecial

    rng20.Copy
    rng22.PasteSpecial


    Set rngk = ws2.Range("ae45")
    fil = ws2.Range("L50:L68").Cells.SpecialCells(xlCellTypeConstants).Count
    rngk.Value = "NUMBER OF DRAWINGS SPECIFY ON THIS SHEET " & fil & ")"




    rngy.Select
    Selection.Copy
    rng22.Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False

    rngh.Select
    Selection.Copy
    rng12.Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False

    rngh.Select
    Selection.Copy
    rng13.Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False

    rngh.Select
    Selection.Copy
    rng11.Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False

    rngo.Select
    Selection.Copy
    rng14.Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False

    ' UP TO HERE IS FOR FIRST FORM AND IT'S WORKING FINE NOW DOWN IN CASE IF DATA IN SHEET 1 IS TOO MANY WHICH NEED MORE THAN ONE
    'FORM





    'If cnt > 1 Then


    For a = 1 To cnt
    g = 36

    rng5.Offset(Y * a, 0).Copy
    rng11.Offset(g * a, 0).PasteSpecial

    rng6.Offset(Y * a, 0).Copy
    rng12.Offset(g * a, 0).PasteSpecial

    rng7.Offset(Y * a, 0).Copy
    rng13.Offset(g * a, 0).PasteSpecial

    rng8.Offset(Y * a, 0).Copy
    rng14.Offset(g * a, 0).PasteSpecial

    rng20.Offset(Y * a, 0).Copy
    rng22.Offset(g * a, 0).PasteSpecial


    Next a



    Dim rngkk As Range
    Dim fill As Long




    Set rngkk = ws2.Range("AE45").Offset(g * a, 0)
    fill = ws2.Range("l50:l68").Offset(i * a, 0).Cells.SpecialCells(xlCellTypeConstants).Count
    rngkk.Value = "NUMBER OF DRAWINGS SPECIFY ON THIS SHEET " & fill & ")"




    For x = 1 To cnt

    rngy.Select
    Selection.Copy
    rng22.Offset(g * x).Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False

    rngh.Select
    Selection.Copy
    rng13.Offset(g * x).Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False

    rngh.Select
    Selection.Copy
    rng12.Offset(g * x).Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False

    rngh.Select
    Selection.Copy
    rng11.Offset(g * x).Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False

    rngo.Select
    Selection.Copy
    rng14.Offset(g * x).Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False


    Next x


    'Else
    'End If


    End Sub



    INFO3.png

  7. #7
    Registered User
    Join Date
    10-07-2018
    Location
    jeddah
    MS-Off Ver
    2007
    Posts
    9

    Re: Counting used cells in forms not working in different places

    This sheet no 1 which i take data from and fill it to the form which i post previously,
    now the code is copy and pasting and arranging everything
    except the last thing which the forms after getting filled , there is a total no of used rows in each form usually max 19 =y
    i=18 which is the distance between each group of rows
    g=36 distance between first range (ae45) and (ae81") to contain the total rows

  8. #8
    Registered User
    Join Date
    10-07-2018
    Location
    jeddah
    MS-Off Ver
    2007
    Posts
    9

    Re: Counting used cells in forms not working in different places

    So the forms below the code which i show you is not giving the total , i don't know where is the misake

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Counting used cells in forms not working in different places

    @zodia77: Please read how to post code in between code tags, it's not that difficult.
    And also what you you expect us to do with attached screenshots? redraw them?

  10. #10
    Registered User
    Join Date
    10-07-2018
    Location
    jeddah
    MS-Off Ver
    2007
    Posts
    9

    Re: Counting used cells in forms not working in different places

    FIRST: SORRY BECAUSE THIS IS THE FIRST TIME FOR ME TO POST IN FORUM
    THE CODE

    Please Login or Register  to view this content.
    SECOND : I PUT THE SCREENSHOT TO GIVE YOU THE FULL IDEA OF DATA AND IT'S PROBLEM, WHEN YOU SAID ( I don't understand the nature of your data.)
    I'M NOT ASKING YOU TO REDRAW ANY THING

  11. #11
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Counting used cells in forms not working in different places

    And, if it's the first time ... start by reading how it works
    I know you don't want me or any of us to redraw anything but the screenshot tells us nothing.
    You screenshot is of Sht1 and your code is sht7 so ?

  12. #12
    Registered User
    Join Date
    10-07-2018
    Location
    jeddah
    MS-Off Ver
    2007
    Posts
    9

    Re: Counting used cells in forms not working in different places

    Sht1 = ws1 is the source sheet
    sht7 = ws2 is the target sheet ( screenshot in the beginning of this thread)

  13. #13
    Registered User
    Join Date
    10-07-2018
    Location
    jeddah
    MS-Off Ver
    2007
    Posts
    9

    Re: Counting used cells in forms not working in different places

    Any idea where is the mistake

  14. #14
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Counting used cells in forms not working in different places

    No, not with a file.
    You should try going step-by-step through the part of the code where you say it is going wrong that's the only way to see were the calculation erro happens.

  15. #15
    Registered User
    Join Date
    10-07-2018
    Location
    jeddah
    MS-Off Ver
    2007
    Posts
    9

    Re: Counting used cells in forms not working in different places

    Thanks for nothing , i did fix it

  16. #16
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Counting used cells in forms not working in different places

    Very good. you see, all it takes is patience and ... time

+ 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. counting decimal places
    By Warren Smith in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-06-2005, 09:05 PM
  2. [SOLVED] counting decimal places
    By Warren Smith in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 09-06-2005, 07:05 PM
  3. counting decimal places
    By Warren Smith in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 06:05 PM
  4. counting decimal places
    By Warren Smith in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 09-06-2005, 05:05 PM
  5. [SOLVED] counting decimal places
    By Warren Smith in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 04:05 PM
  6. [SOLVED] counting decimal places
    By Warren Smith in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  7. counting decimal places
    By Warren Smith in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM
  8. counting decimal places
    By Warren Smith in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 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