Results 1 to 14 of 14

Thread: [RESOLVED] delete rows in excel form using vb

  1. #1

    Thread Starter
    Hyperactive Member wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Resolved [RESOLVED] delete rows in excel form using vb

    hi,
    i want to delete entire rows from the excel form before writing new rows to the excel form.
    is it possible.
    thanks

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: delete rows in excel form using vb

    Quote Originally Posted by wizkid
    hi,
    i want to delete entire rows from the excel form before writing new rows to the excel form.
    is it possible.
    thanks
    When you say form are you really talking about a worksheet?
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    Hyperactive Member wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Re: delete rows in excel form using vb

    sorry,
    i am working on worksheet
    i want to delete the entire rows of the sheet
    thanks

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: delete rows in excel form using vb

    The attached code will delete the entire row based on a single cell. It should be enough to get you started
    VB Code:
    1. Sub SampleDelete()
    2. Dim rngSingleCell As Range
    3.    
    4.     Set rngSingleCell = ThisWorkbook.Worksheets(1).Range("c12")
    5.    
    6.     rngSingleCell.EntireRow.Delete Shift:=xlShiftUp
    7. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  5. #5

    Thread Starter
    Hyperactive Member wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Re: delete rows in excel form using vb

    thanks a lot
    i checked this one with sample code.
    i will continue with this.it is working
    but i got some other problem

    i am getting all the values in worksheet.
    but here i am getting some error

    Application.Workbooks("Book1.xls").Save ...in this line

    like subscript out of range
    why this happens

  6. #6

    Thread Starter
    Hyperactive Member wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Re: delete rows in excel form using vb

    i can't delete the entire rows
    some are still there.
    any suggestions

  7. #7
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: delete rows in excel form using vb

    Can you post your code?
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  8. #8

    Thread Starter
    Hyperactive Member wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Re: delete rows in excel form using vb

    i want to put so manyvalues in work sheets
    c11 means here ??
    i want to delete each and every row
    VB Code:
    1. Set oWB = moApp.Workbooks.Open("C:\Book1.xls")
    2.      oWB.Sheets(1).Activate
    3.     Dim rngSingleCell As Range
    4.    
    5.     Set rngSingleCell = moApp.Worksheets(1).Range("c11")
    6.  
    7.  
    8. i = 2
    9. For qq = 0 To p - 1
    10.  
    11.        oWB.Sheets(1).Cells(i, 1).Value = divide_price_list(qq)
    12.         i = i + 1
    13.        
    14.  Next
    15. i = 2  For qq = 0 To p - 1
    16.       calvalues (divide_price_list(qq)) 'this is function
    17.        
    18.         oWB.Sheets(1).Cells(i, 2).Value = grosssales_rs(1)
    19.         i = i + 1
    20.         grosssales_rs.Close
    21.      
    22.  Next

  9. #9
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: delete rows in excel form using vb

    Quote Originally Posted by wizkid
    i want to put so manyvalues in work sheets
    c11 means here ??
    i want to delete each and every row
    Ok, now I'm confused. Do you want the procedure to add data to the sheet or to delete every row. Please take some time to explain exactly what you want this procedure to achieve.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  10. #10

    Thread Starter
    Hyperactive Member wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Re: delete rows in excel form using vb

    i am getting some value from the procedure,
    and i want to put the procedure returned value in one of the excel worksheet cell.
    like i want to put each and every value(which is returned by the procedure) in the sheet

    before that .,i want to erase the entire worksheet before running the program.
    here i want only one thing how to erase entire contents of the worksheet after open the worksheet.



    VB Code:
    1. Set oWB = moApp.Workbooks.Open("C:\Book1.xls")
    2.      oWB.Sheets(1).Activate
    3.     Dim rngSingleCell As Range
    4.    
    5. '''''here my program starts....
    6. so i want to erase the entire rows in book.xls
    7.  
    8. i = 2
    9. For qq = 0 To p - 1
    10.  
    11.        oWB.Sheets(1).Cells(i, 1).Value = divide_price_list(qq)
    12.         i = i + 1
    13.        
    14.  Next
    15. i = 2  For qq = 0 To p - 1
    16.       calvalues (divide_price_list(qq)) 'this is function
    17.        
    18.         oWB.Sheets(1).Cells(i, 2).Value = grosssales_rs(1)
    19.         i = i + 1
    20.         grosssales_rs.Close
    21.      
    22.  Next


    if it is not clear then please tell me

  11. #11
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: delete rows in excel form using vb

    Quote Originally Posted by wizkid
    here i want only one thing how to erase entire contents of the worksheet after open the worksheet.
    To erase the entire contents of the worksheet, which keeping any cell formatting, use the following syntax.
    VB Code:
    1. Worksheets("YourSheetNameHere").Cells.ClearContents
    You will need to change "YourSheetNameHere" to the name of the sheet that you want to clear

    If you want to clear the formatting as well as the data, then use the following syntax.
    VB Code:
    1. Worksheets("YourSheetNameHere").Cells.Clear
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  12. #12

    Thread Starter
    Hyperactive Member wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Re: delete rows in excel form using vb

    thank you very much dKenny
    it is working well.
    but some times when i open the report first time and i am saving the report using vb code i am getting somw error like,subscript out of range
    what is reason??
    wizkid

  13. #13
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: delete rows in excel form using vb

    Good.

    Don't forget to mark the Thread as resolved.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  14. #14

    Thread Starter
    Hyperactive Member wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Re: delete rows in excel form using vb

    sure

Posting Permissions

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



Click Here to Expand Forum to Full Width