Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all 88749 articles
Browse latest View live

When run a macro system shows popup "Error Automatización" and close Excel

$
0
0

I have an Excel vba project and sometimes when I run a macro (Ctrl + A)

Excel shows a popup and closes the Excel program.

Can you help where is the problem?

enter image description here


Change entire row color if the first characters in a cell is "-"

$
0
0

I would like to change entire row color if the first character of the cells in column A = "-"

Here is my work, I successfully color the row, but it also colored other rows, which the first character of the cells in column A <>"-"

CEll A1 (-ABS) /////////////////// CEll A2 (12345-Surface Import) ----> I don't want this row to be colored

Dim Wb3 As Excel.Workbook
Set Wb3 = Application.Workbooks("Test template.xlsm")

Dim ws As Worksheet

For Each ws In Wb3.Sheets

 Dim SrchRng3 As Range
 Dim c3 As Range, f As String


 Set SrchRng3 = ws.Range("A1", ws.Range("A65536").End(xlUp))
 Set c3 = SrchRng3.Find("-*", LookIn:=xlValues)
 If Not c3 Is Nothing Then
 f = c3.Address
 Do
 With ws.Range("C"& c3.Row & ":N"& c3.Row)
 .Font.ColorIndex = 2
 .Interior.ColorIndex = 24
 End With
 Set c3 = SrchRng3.FindNext(c3)
 Loop While c3.Address <> f
 End If


Next


End Sub

PowerQuery Cell Values Change Suddenly in between first two Applied Steps previews

$
0
0

Merry Christmas Everyone!

So I have a PowerQuery "qryQustion" in an Excel workbook. It joins information from two other queries together for the first line (SOURCE = ...), then the second line expands the joined table's fields.

I adjusted one of the two queries being joined together, and it yields good new results. However, the subject "qryQuestion" query didn't seem to get the updated input, so I began investigating with its applied steps.

Turns out, the first line (SOURCE = ...) yields the good new results. However, the second line yields old results. I checked the expand function and its fields have nothing to do with (no similar names) as the field with values that suddenly go from updated to non-updated.

Here's the essence of the query's beginning:

let
Source = Table.NestedJoin(#"qryInput1Updated",{"Keyfield"},#"qryInput2",{"Keyfield"},"qryInput2",JoinKind.Inner),
#"Expanded Column of Tables of qryInput2 Data" = Table.ExpandTableColumn(Source, "qryInput2", {"AddedField1", "AddedField2", "AddedField3", "AddedField4", "AddedField5", "AddedField6", "AddedField7", "AddedField8", "AddedField9", "AddedField10", "AddedField11", "AddedField12", "AddedField13", "AddedField14", "AddedField15"}, {"AddedField1", "AddedField2", "AddedField3", "AddedField4", "AddedField5", "AddedField6", "AddedField7", "AddedField8", "AddedField9", "AddedField10", "AddedField11", "AddedField12", "AddedField13", "AddedField14", "AddedField15"})
in
#"Expanded Column of Tables of qryInput2 Data"

Why would PowerQuery's preview show different results between Applied Steps?

Is there some sort of "recalculate all" for PowerQuery, or way to force it to recalculate?

How to concatenate text from multiple rows into a single text string in SQL server..? [closed]

$
0
0
select
id,
customer_feedback
from
bigfoot_external_neo.mp_cs__ims_thread_hive_fact
where 
id IN ('IN1912091313273713362',
'IN1912081201470386076',
'IN1912141036434151038',
'IN1912111640244082291',
'IN1912101604439091739')
group by
id

Trying to get data from Excel using c#

$
0
0

Trying to get data from Excel, I got a error in the last line.

private void Button1_Click(object sender, EventArgs e)
        {
            OleDbConnection conn = new OleDbConnection();
            conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Aleksey\Downloads\555\Import Sheet 1532.xlsx" + @";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1;ImportMixedTypes=Text;TypeGuessRows=0""";
            OleDbCommand command = new OleDbCommand
                (
                "SELECT 1532, SUQA " +
                "FORM [SHEET1$]", conn
                );

            DataSet ds1532 = new DataSet();
            OleDbDataAdapter adapter = new OleDbDataAdapter(command);
            adapter.Fill(ds1532);
            dataGridView1532.DataSourse = ds1532.Tables[0];

1532 is the name of the table.

"SUQA" - the title in the table.

I will be glad of any help.

UPD1 Screenshot // name dataGridView1532 does not exist in this context

How to make and edit radar plot with Excel VBA

$
0
0

I'm trying to made my table in excel into a radar plot with my own editing. But when I use record macro, I'm experiencing some error with my VBA as if my editing won't work.

I have some VBA Code like:

Sub Macro6()
'' Macro6 Macro
'' Keyboard Shortcut: Ctrl+Shift+S
'
    Range("A1:C8").DataFields
    ColorIndex..Fill(317, xlRadarFilled).DataFields
    Color.  := Item("Data!$A$1:$C$8")
    Color..DataFields
    With ActiveSheet.Shapes("Chart 8").Fill
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorBackground1
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = -0.25
        .Solid
    End With
    Color..ActiveSheet = "Data"
    Selection.Format.TextFrame2.TextRange.Characters.Text = "Data"
    With Selection.Format.TextFrame2.TextRange.Characters(1, 4).ParagraphFormat
        .TextDirection = msoTextDirectionLeftToRight
        .Alignment = msoAlignCenter
    End With
    With Selection.Format.TextFrame2.TextRange.Characters(1, 4).Font
        .BaselineOffset = 0
        .Bold = msoFalse
        .NameComplexScript = "+mn-cs"
        .NameFarEast = "+mn-ea"
        .Fill.Visible = msoTrue
        .Fill.ForeColor.RGB = RGB(89, 89, 89)
        .Fill.Transparency = 0
        .Fill.Solid
        .Size = 14
        .Italic = msoFalse
        .Kerning = 12
        .Name = "+mn-lt"
        .UnderlineStyle = msoNoUnderline
        .Spacing = 0
        .Strike = msoNoStrike
    End With
    Color..DataFields
    Color.(msoElementLegendRight)
    Color.(2).DataFields
    With Selection.Format.Fill
        .Visible = msoTrue
        .ForeColor.RGB = RGB(0, 0, 0)
        .Transparency = 0.3999999762
        .Solid
    End With
    With Selection.Format.Fill
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorAccent2
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = 0
        .Transparency = 0.3999999762
        .Solid
    End With
    Color.(1).DataFields
    With Selection.Format.Fill
        .Visible = msoTrue
        .ForeColor.RGB = RGB(0, 0, 0)
        .Transparency = 0.3999999762
        .Solid
    End With
    With Selection.Format.Fill
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorAccent1
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = 0
        .Transparency = 0.3999999762
        .Solid
    End With
    Color.(xlValue)..DataFields
    With Selection.Format.Line
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorAccent1
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = 0
    End With
    Color..DataFields
    With Selection.Format.Line
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorText1
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = 0
        .Transparency = 0
    End With
    Selection.Format.Fill.Visible = msoFalse
    With Selection.Format.TextFrame2.TextRange.Font.Shadow
        .Type = msoShadow25
        .Visible = msoTrue
        .Style = msoShadowStyleOuterShadow
        .Blur = 5
        .OffsetX = 2.4492935983E-16
        .OffsetY = 4
        .RotateWithShape = msoFalse
        .ForeColor.RGB = RGB(0, 0, 0)
        .Transparency = 0.5686300099
        .Size = 100
    End With
    Color.(1).ReadingOrder.DataFields
    With Selection.Format.TextFrame2.TextRange.Font.Shadow
        .Type = msoShadow25
        .Visible = msoTrue
        .Style = msoShadowStyleOuterShadow
        .Blur = 4
        .OffsetX = 2.4492935983E-16
        .OffsetY = 4
        .RotateWithShape = msoFalse
        .ForeColor.RGB = RGB(0, 0, 0)
        .Transparency = 0.5686300099
        .Size = 100
    End With
    With Selection.Format.TextFrame2.TextRange.Font.Shadow
        .Type = msoShadow25
        .Visible = msoTrue
        .Style = msoShadowStyleOuterShadow
        .Blur = 0
        .OffsetX = 2.4492935983E-16
        .OffsetY = 4
        .RotateWithShape = msoFalse
        .ForeColor.RGB = RGB(0, 0, 0)
        .Transparency = 0.5686300099
        .Size = 100
    End With
    Color..DataFields
    With Selection.Format.TextFrame2.TextRange.Font.Shadow
        .Type = msoShadow25
        .Visible = msoTrue
        .Style = msoShadowStyleOuterShadow
        .Blur = 4
        .OffsetX = 2.4492935983E-16
        .OffsetY = 4
        .RotateWithShape = msoFalse
        .ForeColor.RGB = RGB(0, 0, 0)
        .Transparency = 0.5686300099
        .Size = 100
    End With
    ActiveSheet.Shapes("Chart 8").IncrementLeft 252.2058267717
    ActiveSheet.Shapes("Chart 8").IncrementTop -120.5882677165
    ActiveSheet.Shapes("Chart 8").IncrementLeft -12.5
    ActiveSheet.Shapes("Chart 8").IncrementTop -24.2647244094
    Color..DataFields
    Color.(1).ReadingOrder.DataFields
    With Selection.Format.TextFrame2.TextRange.Font.Fill
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorText1
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = 0
        .Transparency = 0
        .Solid
    End With
    Color.(xlValue)..DataFields
    With Selection.Format.TextFrame2.TextRange.Font.Fill
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorText1
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = 0
        .Transparency = 0
        .Solid
    End With
    With Selection.Format.Line
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorText1
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = 0
        .Transparency = 0
    End With
End Sub

I Hope that it will output my Radar Plot like I wanted to but it just can't. And I'm not really that fluent in excel VBA.

Thank you very much.

Run macro automatically when cell value changed (not changed by user)

$
0
0

Is there a way to have a macro changed when the value is changed is changed, not necessarily when a user changes the value?

For example, I have a check box that is linked to a cell "A1". When the check box is checked, A1 reads "TRUE" when it is not checked it reads "FALSE". When A1 changes between TRUE and FALSE I want a macro to run.

I have seen the Private Sub Worksheet_Change code, but that seems to only work when a user actually changes cell A1. Is there another way to automatically run the macro?

UPDATE 11/29/13 Thank you everyone for your suggestions, but unfortunately it isn't quite working out. Let me try to expand further.

I have a user form with check boxes, drop down lists, and text fields. All of the data from the user form is summarized in column B of a worksheet (which is where all the user form fields are linked). When the macro runs, some calculations happen and the user get's some numbers.

When the user changes something in the user form I want the macro to run automatically. I know there is a possibility that this can become resource intensive, but I'll deal with that problem when it comes to it. I would like to have a procedure that says if the value of any cell in range B1:B20 changes then run the macro. I believe this method is easier than telling every user form field to run the same macro because it will be easier to expand and update this form later, especially if someone else takes over maintenance.

I could just have a button that the user can click to run the macro when they are done filling in the form, but I can foresee inaccurate information because the user forgets to recalculate; this is why I would like to have it done automatically and numbers are updated in real time.

Excel VBA Range.AutoFilter filtering for equal sign ("=")

$
0
0

I hava a table tbl_recommendations that contains the following values in column 13: --, -, =, +, ++.

Now, I would like to filter for =, +, ++. This is working fine manually, however, I am facing some problems when using VBA regarding filtering for =. Simply using the macro recorder, it gives me the following code:

Sub Test()

ActiveSheet.ListObjects("tbl_recommendations").Range.AutoFilter Field:=13, _
    Criteria1:=Array("+", "++", " = "), Operator:=xlFilterValues

End Sub

When executing this macro, it only filters for + and ++, but not for =. What's the trick?


Set the currency symbol when writing with xlsxwriter

$
0
0

I'm having trouble writing the currency symbol I want in my currency values with xlsxwriter.

I followed the tutorial here and I'm able to write out currency values with the correct formatting and a dollar sign (whether this is from the tutorial or excel's default settings I'm not sure).

This works:

money = workbook.add_format({'num_format':'$#,##0.00'})

And it prints out a currency value with the dollar sign.

$1,000.00

But if I try to insert my own currency, let's say R:

money = workbook.add_format({'num_format':'R#,##0.00'})

I get this:

R1000

How can I set the currency symbol using xlsxwriter?

How to get inner text in html under "id"

$
0
0

i am trying this. I am stuck for my project please help to bring this specific point under "id".

Option Explicit
Public Sub GetlastPrice()
Dim ws As Worksheet, re As Object, p As String, r As String, URL As String

Set ws = ThisWorkbook.Worksheets("Sheet1")
p = """tradedVolume"":""(.*?)"""
Set re = CreateObject("VBScript.RegExp")

URL = "https://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuote.jsp?symbol=PEL"
With CreateObject("MSXML2.XMLHTTP")
    .Open "GET", URL, False
        .setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
        .send
        If .Status = 200 Then
            r = GetValue(re, .responseText, p)
        Else
            r = "Failed connection"
        End If
End With
ws.Range("B2").Value = r


End Sub

Public Function GetValue(ByVal re As Object, ByVal inputString As String, ByVal pattern As String) As String
With re
    .Global = True
    .pattern = pattern
    If .test(inputString) Then  ' returns True if the regex pattern can be matched agaist the provided string
        GetValue = .Execute(inputString)(0).submatches(0)
    Else
        GetValue = "Not found"
    End If
End With
End Function

The marked value i want in my excel sheet

enter image description here

New line in same cell for GROUP_CONCAT when export from html, mysql to excel

$
0
0

I'm using

Select name, GROUP_CONCAT('-', quantity SEPARATOR '\r\n') details ....

mysql query for exporting to excel from html php. It is working and exporting well. Problem is when I export then the file showed like this image

enter image description here GROUP_CONCAT make new cell. But I need all value in a same cell with line break for each value like enter image description here

I have tried

Select name, GROUP_CONCAT('-', quantity SEPARATOR '\r\n') details ....

So how to do it

How do I simplify this

$
0
0

I am attempting to write a code that is applied to old files stored on my hard drive. I have written the code and it works but it rather long and as sections repeat itself it could use some simplifying.

Because the old files change slightly the location of the sum may change which is why I use variables for row references. the code in question is

ws1.Cells(n + first, 52).Formula = "="& Split(Cells(1, 52).Address, "$")(1) & n + first - 1 & "+"& Split(Cells(1, 5).Address, "$")(1) & n + first & "+"& Split(Cells(1, 8).Address, "$")(1) & n + first & "+"& Split(Cells(1, 11).Address, "$")(1) & n + first & "+"& Split(Cells(1, 14).Address, "$")(1) & n + first & "+"& Split(Cells(1, 17).Address, "$")(1) & n + first & "+"& Split(Cells(1, 20).Address, "$")(1) & n + first & "+"& Split(Cells(1, 23).Address, "$")(1) & n + first & "+"& Split(Cells(1, 26).Address, "$")(1) & n + first & "+"& Split(Cells(1, 29).Address, "$")(1) & n + first & "+"& Split(Cells(1, 32).Address, "$")(1) & n + first & "+"& Split(Cells(1, 35).Address, "$")(1) & n + first & "+"& Split(Cells(1, 38).Address, "$")(1) & n + first & "+"& Split(Cells(1, 41).Address, "$")(1) & n + first & "+"& Split(Cells(1, 44).Address, "$")(1) & n + first & "+"& Split(Cells(1, 47).Address, "$")(1) & n + first

As you can see the split is repeated changing by 3 columns each time.

The point of the code is a simply cell(x,y) = cell(x-1,y) + sum....

I believe it would be possible to pass it through a for loop that returns a string that is concatenated?

note: this is in a for loop running through values of n. First is a variable to identify the start of the calculations

any help would be appreciated

Custom function to extract the number from a text column

$
0
0

Please help me with this function.

Function GetPONumber1(PONum As String) As String
    GetPONumber1 = Aplication.WorksheetFunction.Mid(PONum,
                     (Application.WorksheetFunction.Find("2100", PONum, 1)), 10)
End Function

where PONum is the cell location of the text.

I'm trying to write a function to extract the number from a text column.

Python accessing cell from other sheet with openpyxl

$
0
0

I am new to manipulating data via openpyxl and I am trying to write a tool which could help to automatize my work. I have a program which creates an excel with two sheets: read_from and write_to, which will contain some output data.

view

A formula from sheet "write_to" should acces the cell from "Read_to" like this:

enter image description here

however, when I try to do this via python, the line:

write_to_sheet["A2"] = ["=Read_from!B2;"]

throws an exception:

(in _bind_value raise ValueError("Cannot convert {0!r} to Excel".format(value))

What am I doing wrong?

Add data to another table

$
0
0

i have a table("table1") in one sheet.i have a button that adds the data in the table to another table in another sheet("table").every time its overriding the data. i want to add the data("table1") to the table("table2") instead of overriding it. this is the code:

 Sheets("Letter (P V)").ListObjects("Table1").Range.Copy _
      Destination:=Sheets("Actual").Range("E2")

thanks!


automating data entry in a web form using VBA

$
0
0

I am trying to input data into excel and then populate it into a website.
I keep getting an error message saying: "automation error, the interface is unknown".
Is it anything to do with the settings on IE or excel?

Sub test()
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")

With ie
    .Visible = True
    .navigate "http://charterweb.santanderuk.gs.corp/CharterServiceChain/default.aspx"'Wait for loding
    Do While .Busy
    Loop

    Do While .readyState <> 4
        DoEvents
    Loop

End With

Set cmcRef = ie.document.getElementById("M_E_ctlPartField214_V")
cmcRef.Value = "test"

End Sub

VBA: Worksheet_Change - Target.Address vs Working with Intersect

$
0
0

I am successfully running a macro that includes the following piece of code:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$B$1" Or Target.Address = "$B$3" Then
        Call MainSub
    End If
End Sub

The point of this sub is to make the macro spring into action via calling MainSub when Cell B1 or B3 are changed. It works.

However, when looking for a solution on how to do this, I also came across this code:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Target.Worksheet.Range("B1")) Is Nothing Then
        Call MainSub
    End If
End Sub

It works just as well with only B1.

Now I have two questions:

1) How would I include another cell (B3) to check in the intersect method? Using or didn't work for me, so I think another if-Statement after the first one would do the trick, but is there a more elegant solution?

2) What's the advantage of using intersect vs simply looking at Target.Address?

Find the row that met certain criteria with latest date vba

$
0
0

I have this table below. What I am trying to achieve through Excel VBA is loop through the table below to find a person's name at the latest date and give me the units she/he purchased.

enter image description here

?: What is the best or simplest way to get the "Units" purchased on the latest "Meeting Date" when search by "Name"

Let us say I Choose Gerry, the result will give me "30" as it is the units purchased on the latest "Meeting Date" Sorry I am new to Excel VBA.

My challenge also is also after going through all rows that has "gerry", how can I get the row that has the latest date?

I will update the question if it needs some clarification. Thanks.

VBA Macro for Thick Borders on cells (After evaluating if cells in range are >0, need offset)

$
0
0

My VBA code is not running , It is stuck on ActiveCell.Offset.

Sub Borders()
For Each cell In Range("BO5:CL120")

    If cell.Value > 0 Then
            ActiveCell.Offset(0, -54).Range("A1").Select
            ActiveCell.BorderAround _
            ColorIndex:=1, Weight:=xlThick
        Exit For
    End If

Next cell
End Sub

Insert Excel file to PPT slide programattically

$
0
0

enter image description hereIs it possible to insert an excel file as object to MS PPT programatically so that when excel file is clicked in slide, all data would be visible? (as shown in the pic)

Viewing all 88749 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>