calculation by vba

agog12

Board Regular
Joined
Jan 23, 2018
Messages
104
vba is placed in a seperate file c.xlsm
both files are located in a same place
there is a file name sample1.xlsx
open sample1.xlsx
in column N we have to use the formula =H2/M2 and paste the result in values in column N of sample1.xlsx
and in coulmn Q we have to use the formula =N2*P2 and paste the result in values in column Q of sample1.xlsx
and save and close the sample1.xlsx


note we have to use the formula till the end of the data (till the column H has data )
example if column H has data till H17 then we have to use the formula till
N17 & Q17

so plz have a look sir and help me in solving this problem by vba macro sir
 
Then delete all those #N/A from A65537 to H1048576. No wonder that the code from DanteAmor couldn't find the last row that you expected.
Once you have done that the code DanteAmor posted will work as per your original request.
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Did you clear the contents in columns N & Q first?
I just cleared all the #N/A columns N & Q.
Ran the code below, which is just the code by Dante amended to run from the 123 workbook and it runs correctly.

VBA Code:
Sub calculation()
    Dim wb As Workbook, sh As Worksheet, lr As Long
    Set wb = ActiveWorkbook   'Workbooks.Open(ThisWorkbook.Path & "\sample1.xlsx")
    Set sh = wb.Sheets(1)
    lr = sh.Range("H" & Rows.Count).End(3).Row
    With sh.Range("N2:N" & lr)
        .Formula = "=H2/M2"
        .Value = .Value
    End With
    With sh.Range("Q2:Q" & lr)
        .Formula = "=N2*P2"
        .Value = .Value
    End With
    'wb.Close True
End Sub

I.e. it gives me the result below

123 (1).xlsb
ABCDEFGHIJKLMNOPQR
1ExchangeSymbolSeries/ExpiryOpenHighLow Prev CloseLTP
2NSEASHOKLEYEQ7373.9569.569.969.91000.69910.699
3NSEBANKBARODAEQ76.477.673.376.376.31000.76310.763
4NSEBELEQ76.5576.5572.8573.9573.951000.739510.7395
5NSEFEDERALBNKEQ85.9587.1585.185.985.91000.85910.859
6NSEIDFCFIRSTBEQ37.9537.9536.636.836.81000.36810.368
7NSEONGCEQ90.392.789.591.9591.951000.919510.9195
8NSETATAPOWEREQ47.748.5546.0546.746.71000.46710.467
9NSEAPOLLOTYREEQ146147141142.8142.81001.42811.428
10NSECANBKEQ150150.7140.15143.7143.71001.43711.437
11NSECOALINDIAEQ171.55171.8166.75168.4168.41001.68411.684
12NSEDLFEQ203.5204.9193.15201.7201.71002.01712.017
13NSEEQUITASEQ111.5112.55107.05107.85107.851001.078511.0785
14NSEGAILEQ102108.5102104.4104.41001.04411.044
15NSEHINDALCOEQ162162.2154.1155.9155.91001.55911.559
16
17
18
Sheet1
 
Upvote 0
I GOT THE ISSUE POINT WHERE THE PROBLEM OCCURED IT WAS ANOTHER MACRO AND BCOZ OF THAT I WAS METING WITH THAT PROBLEM SIR THNX ALOT SIR
 
Upvote 0
I don't think the macro in the other post is wrong for what you requested. It copies the entire columns as you asked for.
The issue is you have something (well actually a formula) giving the N/A result in those cells.
In the other thread post what is in one of those cells in workbook a, i.e. if it is a formula post the actual formula and someone will have a look at it.
 
Upvote 0
bro coy and paste that file is a csv file and from that we have to copy and paste it to another file i ran the code step by step and that was causing an issue
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,286
Members
449,076
Latest member
kenyanscott

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top