Closed Thread
Results 1 to 5 of 5

Doubt - excel macros

Hybrid View

  1. #1
    Registered User
    Join Date
    11-28-2011
    Location
    chennai
    MS-Off Ver
    Excel 2010
    Posts
    22

    Question Doubt - excel macros

    hi am using the following macro to update all sheets in a work book based on a main sheet, it does not shows any error and does not updates in all sheets.. it was given by one of my friend but it is not working when i tried but it was working at his home am using excel 2010 he uses excel 2007.

    Private Sub btnupdate_click()

    Sheets(”boys”).Select
    Sheets(”boys”).Cells.Select
    Selection.ClearContents

    Sheets(”boys 40-50″).Select
    Sheets(”boys 40-50″).Cells.Select
    Selection.ClearContents

    Sheets(”boys 30-40″).Select
    Sheets(”boys 30-40″).Cells.Select
    Selection.ClearContents

    Sheets(”girls”).Select
    Sheets(”girls”).Cells.Select
    Selection.ClearContents

    Sheets(”girls 40-50″).Select
    Sheets(”girls 30-40″).Cells.Select
    Selection.ClearContents

    Dim strfilename As String
    strfilename = ThisWorkbook.FullName

    Dim cn As ADODB.Connection
    Set cn = New ADODB.Connection

    With cn
    .Provider = “Microdoft.Jet.OLEDB.4.0″
    .Connectionstring = “Data Source=” & strfilename & “;” & _
    “Extended properties = Excel 8.0;”
    .Open
    End With

    Dim rs As ADODB.Recordset
    Dim row As Integer

    ‘boys
    Set rs = New ADODB.Recordset
    rs.Open “SELECT Name,Age,***,Weight FROM [Main database$] where name is NOT NULL and *** = ‘M’”, cn, adopendynamic, adLockBatchoptimistic

    Sheets(”boys”).Select
    Sheets(”boys”).Cells(1, 1) = “Name”
    Sheets(”boys”).Cells(1, 2) = “Age”
    Sheets(”boys”).Cells(1, 3) = “***”
    Sheets(”boys”).Cells(1, 4) = “Weight”

    row = 1
    Do While Not rs.EOF
    Sheets(”boys”).Cells(row + 1, 1) = rs.feilds(”Name”)
    Sheets(”boys”).Cells(row + 1, 2) = rs.feilds(”Age”)
    Sheets(”boys”).Cells(row + 1, 3) = rs.feilds(”***”)
    Sheets(”boys”).Cells(row + 1, 4) = rs.feilds(”Weight”)
    row = row + 1
    rs.Movenext

    Loop

    ‘boys with weight 40-50
    Set rs = New ADODB.Recordset
    rs.Open “SELECT Name,Age,***,Weight FROM [Main database$] where name is NOT NULL and *** = ‘M’ and weight>40 and Weight30 and Weight40 and weight30 and weight<=40", cn, adopendynamic, adLockBatchoptimistic
    Sheets("girls 30-40").Select
    Sheets("girls 30-40").Cells(1, 1) = "Name"
    Sheets("girls 30-40").Cells(1, 2) = "Age"
    Sheets("girls 30-40").Cells(1, 3) = "***"
    Sheets("girls 30-40").Cells(1, 4) = "Weight"

    row = 1
    Do While Not rs.EOF
    Sheets("girls 30-40").Cells(row + 1, 1) = rs.feilds("Name")
    Sheets("girls 30-40").Cells(row + 1, 2) = rs.feilds("Age")
    Sheets("girls 30-40").Cells(row + 1, 3) = rs.feilds("***")
    Sheets("girls 30-40").Cells(row + 1, 4) = rs.feilds("Weight")
    row = row + 1
    rs.Movenext

    Loop

    Sheets("Main database").Sheet
    MsgBox "upload successfully"
    cn.Close
    Set cn = Nothing
    End Sub
    Attached Files Attached Files
    Last edited by sriram170; 12-17-2011 at 10:13 AM.

  2. #2
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Doubt - excel macros

    Hi and welcome to the board. Unfortunately,

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Doubt - excel macros

    Also, your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    PLEASE PM WHEN YOU HAVE DONE THIS AND I WILL DELETE THIS POST
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    11-28-2011
    Location
    chennai
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Doubt - excel macros

    boss if you can give solution dont get tensed and speak about rules

  5. #5
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Doubt - excel macros

    Maybe you should try starting a new thread after checking the forum rules. I will close this one then.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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